{"id":29996726,"url":"https://github.com/djaus2/myconsole","last_synced_at":"2025-08-05T02:54:29.851Z","repository":{"id":308157017,"uuid":"1031728365","full_name":"djaus2/MyConsole","owner":"djaus2","description":"Simple C# Console app that demonstrates how to get 2 commandline or app settings parameters","archived":false,"fork":false,"pushed_at":"2025-08-04T12:05:29.000Z","size":21,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-08-04T15:47:37.800Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/djaus2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-04T08:40:42.000Z","updated_at":"2025-08-04T12:05:33.000Z","dependencies_parsed_at":"2025-08-04T15:47:39.430Z","dependency_job_id":"3097fa7f-4909-4589-8723-1a7a8e9d33f4","html_url":"https://github.com/djaus2/MyConsole","commit_stats":null,"previous_names":["djaus2/myconsole"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/djaus2/MyConsole","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djaus2%2FMyConsole","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djaus2%2FMyConsole/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djaus2%2FMyConsole/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djaus2%2FMyConsole/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/djaus2","download_url":"https://codeload.github.com/djaus2/MyConsole/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djaus2%2FMyConsole/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268825602,"owners_count":24313268,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-05T02:00:12.334Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-08-05T02:54:25.140Z","updated_at":"2025-08-05T02:54:29.825Z","avatar_url":"https://github.com/djaus2.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MyConsole Application\n\nA C# console application that demonstrates configuration management with the following features:\n\n- Configuration properties:\n  - `Folder` (string)\n  - `Port` (int)\n- Configuration sources (in order of precedence):\n  1. Command line arguments\n  2. appsettings.json file\n- Automatically saves the used configuration values back to appsettings.json\n\n\u003e Configuration code is in a companion project\n\n## Projecvts\n- MyConsole: The console app\n- ConfigurationManager: The backend lib\n\n## Building and Running\n\n### Prerequisites\n- .NET 9.0 SDK or later\n\n### Build\n```\ndotnet build\n```\n\n### Run\n```\ndotnet run\n```\n\n### Run with command line arguments\nYou can now use simplified command line arguments:\n\n```\n# Using long form arguments\ndotnet run -- --folder \"C:\\CustomFolder\" --port 9090\n\n# Using short form arguments\ndotnet run -- -f \"C:\\CustomFolder\" -p 9090\n\n# Using equals sign\ndotnet run -- --folder=\"C:\\CustomFolder\" --port=9090\n```\n\nThe original format is also still supported:\n```\ndotnet run -- --AppSettings:Folder=\"C:\\CustomFolder\" --AppSettings:Port=9090\n```\n\n## Running the Built Application\n\nAfter building the application, you can run the executable directly:\n\n```\nMyConsole.exe\n```\n\nWhen running the built application, you can use the same command-line arguments as with `dotnet run`, but without the `--` separator:\n\n```\n# Using long form arguments\nMyConsole.exe --folder \"C:\\CustomFolder\" --port 9090\n\n# Using short form arguments\nMyConsole.exe -f \"C:\\CustomFolder\" -p 9090\n\n# Using equals sign\nMyConsole.exe --folder=\"C:\\CustomFolder\" --port=9090\n```\n\n## Configuration\n\nThe application reads configuration from `appsettings.json` by default:\n\n```json\n{\n  \"AppSettings\": {\n    \"Folder\": \"C:\\\\DefaultFolder\",\n    \"Port\": 8080\n  }\n}\n```\n\nCommand line arguments override the settings in the JSON file. The application saves the final configuration values back to the `appsettings.json` file.\n\n## ConfigurationManager Library\n\nThis project now uses a separate `ConfigurationManager` library that has been extracted from the original code. The library provides a reusable way to handle configuration and command-line arguments.\n\n### Library Features\n\n- Generic configuration processing with type safety\n- Support for multiple configuration sources with precedence\n- Command-line argument parsing with both long and short forms\n- Automatic saving of settings back to JSON files\n\n### Using the Library in Your Projects\n\n1. Add a reference to the ConfigurationManager project:\n   ```xml\n   \u003cProjectReference Include=\"..\\ConfigurationManager\\ConfigurationManager.csproj\" /\u003e\n   ```\n\n2. Create a settings class that inherits from `AppSettingsBase`:\n   ```csharp\n   public class YourSettings : AppSettingsBase\n   {\n       public string SomeSetting { get; set; }\n       public int AnotherSetting { get; set; }\n       \n       public override string SectionName =\u003e \"YourSettingsSection\";\n       \n       public override string ToString()\n       {\n           return $\"SomeSetting: {SomeSetting}, AnotherSetting: {AnotherSetting}\";\n       }\n   }\n   ```\n\n3. Define command-line option mappings:\n   ```csharp\n   var optionsMap = new Dictionary\u003cstring, (string LongName, string ShortName)\u003e\n   {\n       { \"SomeSetting\", (\"some-setting\", \"s\") },\n       { \"AnotherSetting\", (\"another-setting\", \"a\") }\n   };\n   ```\n\n4. Create and use the configuration processor:\n   ```csharp\n   var configProcessor = new ConfigurationProcessor\u003cYourSettings\u003e(\n       \"your-settings.json\",\n       optionsMap,\n       defaultSettings);\n       \n   var settings = configProcessor.ProcessConfiguration(args);\n   ```\n\nThis approach allows you to easily add configuration capabilities to any application with minimal code.\n\n---\n\nThis was created in 2 steps using [Windsurf](https://windsurf.com/)\n\n# Plan for Extracting Command-line/Configuration Logic to a Library\n\n## Notes\n- The user has published the MyConsole project to GitHub.\n- User requested to extract the configuration/command-line argument logic into a separate C# library project for reuse.\n- The current implementation supports both long form and short form command-line arguments for configuration.\n- We have analyzed AppSettings.cs and Program.cs to identify extractable logic (argument processing, config loading, settings persistence).\n- The user has created the ConfigurationManager library project and installed required NuGet packages.\n- The core library classes (AppSettingsBase, CommandLineParser, ConfigurationProcessor) have been implemented in the ConfigurationManager project.\n- MyConsole now references the ConfigurationManager library and uses it for configuration/command-line logic.\n\n## Task List\n- [x] Confirm current command-line/configuration implementation in MyConsole\n- [x] Add documentation to README about argument usage\n- [x] Publish project to GitHub\n- [x] Plan and create a new C# class library project for configuration logic\n- [x] Refactor shared logic from MyConsole into the new library\n- [x] Reference and use the new library in MyConsole\n- [x] Update documentation (README) to reflect library usage\n\n## Current Goal\nProject complete\n\n\nGreat! We've successfully completed all the tasks for extracting the configuration functionality into a separate library. Here's a summary of what we've accomplished:\n1.\tCreated a new \nConfigurationManager\n library project with three main classes:\n•\tAppSettingsBase\n: A base class for settings objects\n•\tCommandLineParser\n: Handles parsing command-line arguments in both long and short forms\n•\tConfigurationProcessor\n: Core class for loading, processing, and saving configuration\n2.\tUpdated the \nMyConsole\n project to use the new library:\n•\tModified \nAppSettings.cs to inherit from \nAppSettingsBase\n•\tSimplified \nProgram.cs to use the \nConfigurationProcessor\n•\tAdded a project reference to the \nConfigurationManager\n library\n3.\tUpdated the README.md with documentation on how to use the new library in other projects\nThe refactored code is now more maintainable, reusable, and follows better separation of concerns. The \nConfigurationManager\n library can be used in any C# application that needs configuration management with command-line argument support.\nWould you like me to explain any specific part of the implementation in more detail?\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdjaus2%2Fmyconsole","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdjaus2%2Fmyconsole","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdjaus2%2Fmyconsole/lists"}