Skip to content

Commit

Permalink
Make options and note high compat level with git config
Browse files Browse the repository at this point in the history
  • Loading branch information
kzu committed Jun 25, 2024
1 parent e47face commit 90333f1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
19 changes: 13 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,11 @@ Installation is the same as for any other dotnet tool:
> dotnet tool install -g dotnet-config
```
The available options and actions are (for the most part) compatible with the behavior of `git config`.
> When reading and writing from a single file, you can for the most part just use `git config`
> along with the compatibility option `-f|--file` specifying the file to read/write from.
Reading and writing variables don't require any special options. The following lines first
write a variable value and then retrieve its value:
Expand All @@ -504,29 +509,31 @@ All current options from running `dotnet config -?` are:
Usage: dotnet config [options]

Location (uses all locations by default)
--local use .netconfig.user file
--global use global config file
--system use system config file
--local use .netconfig.user file
-f, --file use given config file (git config compat)
--path[=VALUE] use given config file or directory

Action
--get get value: name [value-regex]
--get-all get all values: key [value-regex]
--get-regexp get values for regexp: name-regex [value-regex]
--set set value: name value [value-regex]
--set-all set all matches: name value [value-regex]
--add add a new variable: name value
--unset remove a variable: name [value-regex]
--unset-all remove all matches: name [value-regex]
--remove-section remove a section: name
--set set value: name value [value-regex]
--set-all set all matches: name value [value-regex]
--rename-section rename section: old-name new-name
--remove-section remove a section: name
-l, --list list all
-e, --edit edit the config file in an editor

Other
--default[=VALUE] with --get, use default value when missing entry
--name-only show variable names only
--type[=VALUE] value is given this type, can be 'boolean', 'datetime' or 'number'
--default[=VALUE] with --get, use default value when missing entry
--type[=VALUE] value is given this type, can be 'boolean', '
datetime' or 'number'
-?, -h, --help Display this help
```
Expand Down
23 changes: 16 additions & 7 deletions src/Config.Tool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ static int Run(string[] args)
var useSystem = false;
var useGlobal = false;
var useLocal = false;
var path = Directory.GetCurrentDirectory();
string? path = default;
string? file = default;
var nameOnly = false;
string? defaultValue = default;
string? type = default;
Expand All @@ -41,35 +42,37 @@ static int Run(string[] args)
{ Environment.NewLine },
{ Environment.NewLine },
{ "Location (uses all locations by default)" },
{ "local", "use .netconfig.user file", _ => useLocal = true },
{ "global", "use global config file", _ => useGlobal = true },
{ "system", "use system config file", _ => useSystem = true },
{ "path:", "use given config file or directory", f => path = f },
{ "local", "use .netconfig.user file", _ => useLocal = true },
{ "f|file", "use given config file (git config compat)", f => file = f },
{ "path:", "use given config file or directory", p => path = p },

{ Environment.NewLine },
{ "Action" },
{ "get", "get value: name [value-regex]", _ => action = ConfigAction.Get },
{ "get-all", "get all values: key [value-regex]", _ => action = ConfigAction.GetAll },
{ "get-regexp", "get values for regexp: name-regex [value-regex]", _ => action = ConfigAction.GetRegexp },
{ "set", "set value: name value [value-regex]", _ => action = ConfigAction.Set },
{ "set-all", "set all matches: name value [value-regex]", _ => action = ConfigAction.SetAll },
{ "replace-all", "replace all matches: name value [value-regex]", _ => action = ConfigAction.SetAll, true },

//{ "get-urlmatch", "get value specific for the URL: section[.var] URL", _ => action = ConfigAction.Get },
{ "add", "add a new variable: name value", _ => action = ConfigAction.Add },
{ "unset", "remove a variable: name [value-regex]", _ => action = ConfigAction.Unset },
{ "unset-all", "remove all matches: name [value-regex]", _ => action = ConfigAction.UnsetAll },

{ "remove-section", "remove a section: name", _ => action = ConfigAction.RemoveSection },
{ "set", "set value: name value [value-regex]", _ => action = ConfigAction.Set },
{ "set-all", "set all matches: name value [value-regex]", _ => action = ConfigAction.SetAll },

{ "rename-section", "rename section: old-name new-name", _ => action = ConfigAction.RenameSection },
{ "remove-section", "remove a section: name", _ => action = ConfigAction.RemoveSection },

{ "l|list", "list all", _ => action = ConfigAction.List },
{ "e|edit", "edit the config file in an editor", _ => action = ConfigAction.Edit },

{ Environment.NewLine },
{ "Other" },
{ "default:", "with --get, use default value when missing entry", v => defaultValue = v },
{ "name-only", "show variable names only", _ => nameOnly = true },
{ "default:", "with --get, use default value when missing entry", v => defaultValue = v },
{ "type:", "value is given this type, can be 'boolean', 'datetime' or 'number'", t => type = t },
{ "debug", "add some extra logging for troubleshooting purposes", _ => debug = true, true },

Expand All @@ -95,6 +98,12 @@ static int Run(string[] args)
return ShowError("Can only specify one config location.");
}

if (file != null && !File.Exists(file))
return ShowError($"Specified config file {file} not found.");

// --file overrides --path since it's more specific.
path = file ?? path ?? Directory.GetCurrentDirectory();

ConfigLevel? level = null;
Config config;
if (useGlobal)
Expand Down

0 comments on commit 90333f1

Please sign in to comment.