How to use the positional function from yargs
Find comprehensive JavaScript yargs.positional code examples handpicked from public code repositorys.
yargs.positional is a method in the yargs library that allows you to specify positional arguments in a command line interface.
GitHub: dockerizeme/dockerizeme
56 57 58 59 60 61 62 63 64 65
type: 'string', describe: 'Rules to use for transitive dependency resolution.', choices: ['deps', 'assoc'] }); yargs.positional('package', { type: 'string', describe: 'Path to the code package to be dockerized. Can be relative to cwd.', default: '.' });
GitHub: mapbox/mapbox-base
162 163 164 165 166 167 168 169 170 171
yargs .command('generate [path]', 'automatically generate a new lock file for repository', (yargs) => yargs.positional('path', {describe: 'path to git repository', default: './'}), (argv) => generateLockFileForRepo(argv.path).then((lf) => console.log(lockFileToString(lf)))) .command('check [path]', 'check licenses against repository\'s lock file', (yargs) => yargs.positional('path', {describe: 'path to git repository', default: './'}),
+ 19 other calls in file
How does yargs.positional work?
yargs.positional()
is a method in the Yargs library that allows you to define and parse positional arguments passed to a command-line interface (CLI) program.
This method lets you define the positional arguments, specify their data types and provide optional configuration options, such as specifying default values and making them required.
When the program is run, Yargs will parse the positional arguments and pass them to the callback function provided in the .command()
method.
7 8 9 10 11 12 13 14 15 16
.usage('$0 <cmd> [args]') .command( 'init <name>', 'Initialize an empty starter project with the given name where you can write the code for your framework', (yargs) => { return yargs.positional('name', { describe: 'name of the framework', type: 'string', }) },
GitHub: spheronFdn/sdk
76 77 78 79 80 81 82 83 84 85
) .wrap(100) .help(); }) .command("get <resource>", "Get resource/s <<resource>>", (yargs: any) => { yargs.positional("resource", { describe: "The resource to get information about", choices: Object.values(ResourceEnum), }); yargs.version(false).wrap(150).help();
Ai Example
1 2 3 4 5 6 7 8 9 10 11
const yargs = require("yargs"); yargs.command({ command: "test ", describe: "Test a file", handler: (argv) => { console.log(`Testing file: ${argv.filename}`); }, }); yargs.parse();
Here, test defines a positional argument called filename, which is accessed through argv.filename in the handler function. When the user runs the command node app.js test file.txt, the output will be Testing file: file.txt.
GitHub: 2003scape/rsc-sprites
38 39 40 41 42 43 44 45 46
.version(pkg.version) .command( 'dump-sprites <config> <archive>', 'dump sprites PNGs from entitiy, media or textures jag/mem archives', (yargs) => { yargs.positional('config', { description: 'config jag archive', type: 'string' });
+ 3 other calls in file
48 49 50 51 52 53 54 55 56 57 58
const Server = new server.Server(ProcessController) // Parse the arguments on initialization const argv = yargs .command('start', 'Whether or not to immediately start python process or not', (yargs) => { yargs.positional('start', { type: 'boolean', default: true, describe: 'Whether to start process immediately' })
GitHub: quantcdn/quant-cli
19 20 21 22 23 24 25 26 27 28 29
const command = {}; command.command = 'deploy [dir]'; command.describe = 'Deploy the output of a static generator'; command.builder = (yargs) => { yargs.positional('dir', { describe: 'Optional location of build artefacts ', type: 'string', default: null, });
yargs.argv is the most popular function in yargs (1012 examples)