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

args: define args using dart method signature #12272

Closed
DartBot opened this issue Aug 6, 2013 · 5 comments
Closed

args: define args using dart method signature #12272

DartBot opened this issue Aug 6, 2013 · 5 comments
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Aug 6, 2013

This issue was originally filed by @seaneagan


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);

@sethladd
Copy link
Contributor

sethladd commented Aug 6, 2013

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

@DartBot
Copy link
Author

DartBot commented Dec 17, 2013

This comment was originally written 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.

@anders-sandholm
Copy link
Contributor

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

@munificent
Copy link
Member

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


Added WontFix label.

@DartBot DartBot added Type-Enhancement area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. labels Jul 15, 2014
@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

This issue has been moved to dart-lang/args#19.

@kevmoo kevmoo added closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug and removed priority-unassigned labels Mar 1, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants