Skip to content

args: define args using dart method signature #117

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

Closed
DartBot opened this issue Jun 5, 2015 · 4 comments
Closed

args: define args using dart method signature #117

DartBot opened this issue Jun 5, 2015 · 4 comments
Labels
closed-not-planned Closed as we don't intend to take action on the reported issue package:args type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/444270?v=3" align="left" width="96" height="96"hspace="10"> Issue by seaneagan
Originally opened as dart-lang/sdk#12272


The args of a command line script seem to map nicely to the args of a dart method. It would be nice to be able to define script args using the same techniques as dart methods, and be able to automatically forward script args to said method. Presumably both of these could be done using a mirror on the method.

Say we have a script called 'greet.dart':

    import 'package:args/args.dart' as args;
    
    main() => args.forward(_main);

    greet(String salutation, String name, [String punctuation = '']) =>
        print('$salutation $name$punctuation);

where _main could be defined using String positional arguments:

    // example:
    // some_script.dart John Hi
    _main(String name, [String salutation = 'Hello']) =>
        greet(salutation, name);

or String or bool named arguments:

    // example:
    // some_script.dart --salutation Hi --exclaim John
    _main(String name, {String salutation: 'Hello ', bool exclaim: false}) =>
        greet(salutation, name, exclaim ? '!' : '');

or with the trailing positional parameter being a List<String>:

    // example:
    // some_script.dart --salutation Hi Bob Alice
    _main(List<String> rest, {String salutation: 'Hello '}) =>
        greet(salutation, rest.join(', '));

If dart ever gets true rest arguments those could be used instead.

To add "help", comments on each arg would make sense, but that is against the dart style guide. For this and other arg metadata, dart's metadata could be used:

    _main(
        String name, {
        @­Arg(abbr: 's', 'How to greet them')
        String salutation: 'Hello ',
        @­Arg(abbr: 'p', help: 'Whether to includ a "!"', allowedHelp: const {'': 'none', '!': 'exclamation'})
        String punctuation = ''}) =>
        greet(salutation, name, punctuation);

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/5479?v=3" align="left" width="48" height="48"hspace="10"> Comment by sethladd


Removed Type-Defect label.
Added Type-Enhancement, Area-Pkg, Library-Args, Triaged labels.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/444270?v=3" align="left" width="48" height="48"hspace="10"> Comment by seaneagan


This is now implemented as:

http://pub.dartlang.org/packages/unscripted

I think it is probably beyond the scope of the "args" package, in which case this bug can be closed.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/3276024?v=3" align="left" width="48" height="48"hspace="10"> Comment by anders-sandholm


Removed Library-Args label.
Added Pkg-Args label.

@DartBot DartBot added type-enhancement A request for a change that isn't a bug closed-not-planned Closed as we don't intend to take action on the reported issue labels Jun 5, 2015
@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/46275?v=3" align="left" width="48" height="48"hspace="10"> Comment by munificent


Yeah, this is a swell idea but I want to avoid using mirrors in args.


Added WontFix label.

@mosuem mosuem transferred this issue from dart-archive/args Oct 14, 2024
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-not-planned Closed as we don't intend to take action on the reported issue package:args type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

2 participants