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

Add function to retrieve actual input values for command options by name #284

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

fa0311
Copy link

@fa0311 fa0311 commented Sep 16, 2024

  • Thanks for your contribution! Please replace this text with a description of what this PR is changing or adding and why, list any relevant issues, and review the contribution guidelines below.

  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.

Motivation to add this.

import 'package:args/args.dart';

void main(List<String> args) {
  var parser = ArgParser();
  parser.addOption('size', abbr: 's', defaultsTo: '20');

  var results = parser.parse(args);

  var size = int.tryParse(results.option('size')!);

  if (size == null) {
    print('Could not parse the ${results.actual('size')} as an integer');
  } else {
    print('The size is $size');
  }
}
$ dart sample.dart --size aa
Could not parse the --size as an integer
$ dart sample.dart -s aa
Could not parse the -s as an integer

Signed-off-by: ふぁ <yuki@yuki0311.com>
Signed-off-by: ふぁ <yuki@yuki0311.com>
Signed-off-by: ふぁ <yuki@yuki0311.com>
Signed-off-by: ふぁ <yuki@yuki0311.com>
Signed-off-by: ふぁ <yuki@yuki0311.com>
Signed-off-by: ふぁ <yuki@yuki0311.com>
Signed-off-by: ふぁ <yuki@yuki0311.com>
@fa0311 fa0311 force-pushed the add-actual-input-value branch 2 times, most recently from f495522 to d9d29af Compare September 25, 2024 03:20
Signed-off-by: ふぁ <yuki@yuki0311.com>
Signed-off-by: ふぁ <yuki@yuki0311.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant