Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

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

Closed
wants to merge 2 commits into from

Conversation

fa0311
Copy link
Contributor

@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

@fa0311 fa0311 force-pushed the add-actual-input-value branch 4 times, most recently from 98d0a31 to 3a3ff12 Compare September 25, 2024 04:01
@fa0311 fa0311 marked this pull request as ready for review October 2, 2024 01:11
@mosuem
Copy link
Contributor

mosuem commented Oct 14, 2024

Closing as the dart-lang/args repository is merged into the dart-lang/core monorepo. Please re-open this PR there!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants