Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Config.arraySep to valueSep #184

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

* `Config.addHelp` is renamed to `Config.addHelpArgument`.

* `Config.arraySep` is renamed to `Config.valueSep`.

* `Style.namedArgumentName` is renamed to `Style.argumentName`.

* Underlying type of `ansiStylingArgument` argument is changed. It can now be directly cast to boolean instead comparing against `Config.StylingMode`.
Expand Down
2 changes: 1 addition & 1 deletion docs/code_snippets/config_arraySep.d
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ T t1;
assert(CLI!T.parseArgs(t1, ["-a","1:2:3","-a","4","5"]));
assert(t1 == T(["1:2:3","4","5"]));

enum Config cfg = { arraySep: ':' };
enum Config cfg = { valueSep: ':' };

T t2;
assert(CLI!(cfg, T).parseArgs(t2, ["-a","1:2:3","-a","4","5"]));
Expand Down
2 changes: 1 addition & 1 deletion docs/code_snippets/types_array_comma.d
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct T
int[] a;
}

enum Config cfg = { arraySep: ',' };
enum Config cfg = { valueSep: ',' };

T t;
assert(CLI!(cfg, T).parseArgs(t, ["-a=1,2,3","-a","4,5"]));
Expand Down
2 changes: 1 addition & 1 deletion docs/code_snippets/types_assoc_array_comma.d
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct T
int[string] a;
}

enum Config cfg = { arraySep: ',' };
enum Config cfg = { valueSep: ',' };

T t;
assert(CLI!(cfg, T).parseArgs(t, ["-a=foo=3,boo=7","-a","bar=4,baz=9"]));
Expand Down
4 changes: 2 additions & 2 deletions docs/topics/Supported-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ The difference can be easily shown in the following example:

<code-block src="code_snippets/types_array.d" lang="c++"/>

Alternatively one can set [`Config.arraySep`](Config.md#arraySep) to allow multiple elements in one command line entry:
Alternatively one can set [`Config.valueSep`](Config.md#valueSep) to allow multiple elements in one command line entry:

<code-block src="code_snippets/types_array_comma.d" lang="c++"/>

Expand All @@ -57,7 +57,7 @@ format of the value is `key=value` (equal sign can be customized with [`Config.a

<code-block src="code_snippets/types_assoc_array.d" lang="c++"/>

Alternatively one can set [`Config.arraySep`](Config.md#arraySep) to allow multiple elements in one command line entry:
Alternatively one can set [`Config.valueSep`](Config.md#valueSep) to allow multiple elements in one command line entry:

<code-block src="code_snippets/types_assoc_array_comma.d" lang="c++"/>

Expand Down
6 changes: 3 additions & 3 deletions docs/topics/reference/Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ Example:

<code-block src="code_snippets/config_assignChar.d" lang="c++"/>

## Array separator {id="arraySep"}
## Value separator {id="valueSep"}

When `Config.arraySep` is set to `char.init`, values to array and associative-array receivers are treated as an individual
value. That is, only one argument is appended/inserted per appearance of the argument. If `arraySep` is set to something
When `Config.valueSep` is set to `char.init`, values to array and associative-array receivers are treated as an individual
value. That is, only one argument is appended/inserted per appearance of the argument. If `valueSep` is set to something
else, then each value is first split by the separator, and the individual pieces are treated as values to the same
argument.

Expand Down
4 changes: 2 additions & 2 deletions source/argparse/config.d
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ struct Config
/**
When set to char.init, parameters to array and associative array receivers are
treated as an individual argument. That is, only one argument is appended or
inserted per appearance of the option switch. If `arraySep` is set to
inserted per appearance of the option switch. If `valueSep` is set to
something else, then each parameter is first split by the separator, and the
individual pieces are treated as arguments to the same option.

Defaults to char.init
*/
char arraySep = char.init;
char valueSep = char.init;

/**
The prefix for argument name.
Expand Down
8 changes: 4 additions & 4 deletions source/argparse/internal/valueparser.d
Original file line number Diff line number Diff line change
Expand Up @@ -490,21 +490,21 @@ unittest

private void splitValues(ref RawParam param)
{
if(param.config.arraySep == char.init)
if(param.config.valueSep == char.init)
return;

import std.array : array, split;
import std.algorithm : map, joiner;

param.value = param.value.map!((string s) => s.split(param.config.arraySep)).joiner.array;
param.value = param.value.map!((string s) => s.split(param.config.valueSep)).joiner.array;
}

unittest
{
alias test = (char arraySep, string[] values)
alias test = (char valueSep, string[] values)
{
Config config;
config.arraySep = arraySep;
config.valueSep = valueSep;

auto param = RawParam(&config, "", values);

Expand Down
6 changes: 3 additions & 3 deletions source/argparse/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ unittest

enum cfg = {
Config cfg;
cfg.arraySep = ',';
cfg.valueSep = ',';
return cfg;
}();

Expand All @@ -636,7 +636,7 @@ unittest

enum cfg = {
Config cfg;
cfg.arraySep = ',';
cfg.valueSep = ',';
return cfg;
}();

Expand Down Expand Up @@ -686,7 +686,7 @@ unittest

enum cfg = {
Config cfg;
cfg.arraySep = ',';
cfg.valueSep = ',';
return cfg;
}();

Expand Down