-
-
Notifications
You must be signed in to change notification settings - Fork 243
replace std.variant with std.sumtype #2550
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,7 @@ import dub.packagesuppliers; | |
| import dub.project; | ||
| import dub.internal.utils : getDUBVersion, getClosestMatch, getTempFile; | ||
|
|
||
| import dub.internal.dyaml.stdsumtype; | ||
| import dub.internal.stdsumtype; | ||
|
|
||
| import std.algorithm; | ||
| import std.array; | ||
|
|
@@ -35,7 +35,6 @@ import std.process; | |
| import std.stdio; | ||
| import std.string; | ||
| import std.typecons : Tuple, tuple; | ||
| import std.variant; | ||
| import std.path: setExtension; | ||
|
|
||
| /** Retrieves a list of all available commands. | ||
|
|
@@ -575,8 +574,10 @@ struct CommonOptions { | |
| */ | ||
| class CommandArgs { | ||
| struct Arg { | ||
| Variant defaultValue; | ||
| Variant value; | ||
| alias Value = SumType!(string[], string, bool, int, uint); | ||
|
|
||
| Value defaultValue; | ||
| Value value; | ||
| string names; | ||
| string[] helpText; | ||
| bool hidden; | ||
|
|
@@ -630,20 +631,25 @@ class CommandArgs { | |
|
|
||
| void getopt(T)(string names, T* var, string[] help_text = null, bool hidden=false) | ||
| { | ||
| import std.traits : OriginalType; | ||
|
|
||
| foreach (ref arg; m_recognizedArgs) | ||
| if (names == arg.names) { | ||
| assert(help_text is null, format!("Duplicated argument '%s' must not change helptext, consider to remove the duplication")(names)); | ||
| *var = arg.value.get!T; | ||
| *var = arg.value.match!( | ||
| (OriginalType!T v) => cast(T)v, | ||
| (_) => assert(false, "value from previous getopt has different type than the current getopt call")) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't that return incorrect results if the previous getopt call set a value outside of T's bounds ?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes that could happen, but I think the previous code would have done the same. (just doing it inside the standard library and not in DUB) - It's just an issue for when the programmer makes a mistake anyway and can't usually be caused by the user doing something. |
||
| ; | ||
| return; | ||
| } | ||
| assert(help_text.length > 0); | ||
| Arg arg; | ||
| arg.defaultValue = *var; | ||
| arg.defaultValue = Arg.Value(cast(OriginalType!T)*var); | ||
|
WebFreak001 marked this conversation as resolved.
Outdated
|
||
| arg.names = names; | ||
| arg.helpText = help_text; | ||
| arg.hidden = hidden; | ||
| m_args.getopt(config.passThrough, names, var); | ||
| arg.value = *var; | ||
| arg.value = Arg.Value(cast(OriginalType!T)*var); | ||
| m_recognizedArgs ~= arg; | ||
| } | ||
|
|
||
|
|
@@ -2694,13 +2700,16 @@ private void writeOptions(CommandArgs args) | |
| } else writeWS(longArgColumn); | ||
| size_t col = longArgColumn; | ||
| if (larg !is null) { | ||
| if (arg.defaultValue.peek!bool) { | ||
| writef("--%s", larg); | ||
| col += larg.length + 2; | ||
| } else { | ||
| writef("--%s=VALUE", larg); | ||
| col += larg.length + 8; | ||
| } | ||
| arg.defaultValue.match!( | ||
| (bool b) { | ||
| writef("--%s", larg); | ||
| col += larg.length + 2; | ||
| }, | ||
| (_) { | ||
| writef("--%s=VALUE", larg); | ||
| col += larg.length + 8; | ||
| } | ||
| ); | ||
| } | ||
| if (col < descColumn) { | ||
| writeWS(descColumn - col); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.