説明なし

parents.js 721B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env node
  2. 'use strict';
  3. var ArgumentParser = require('../lib/argparse').ArgumentParser;
  4. var args;
  5. var parent_parser = new ArgumentParser({ addHelp: false });
  6. // note addHelp:false to prevent duplication of the -h option
  7. parent_parser.addArgument(
  8. ['--parent'],
  9. { type: 'int', description: 'parent' }
  10. );
  11. var foo_parser = new ArgumentParser({
  12. parents: [ parent_parser ],
  13. description: 'child1'
  14. });
  15. foo_parser.addArgument(['foo']);
  16. args = foo_parser.parseArgs(['--parent', '2', 'XXX']);
  17. console.log(args);
  18. var bar_parser = new ArgumentParser({
  19. parents: [ parent_parser ],
  20. description: 'child2'
  21. });
  22. bar_parser.addArgument(['--bar']);
  23. args = bar_parser.parseArgs(['--bar', 'YYY']);
  24. console.log(args);