remote
with two sub-commans - add
and rm
. Each of these sub-commands will require one or more values. I'm struggling to achieve that. The closes I found was "positionals", but I can't figure out how to say that there should be at least one "positional" specified and how to say for which positional the number of required values. How is this supposed to be done with yargs? Here is what I have so far:
const yargs = require('yargs');
yargs.command(
'remote',
'Manage a remote,
(yargs) => {
yargs.positional('add', {
describe: 'Adds a remote',
type: 'string'
});
yargs.positional('rm', {
describe: 'Remove a remote',
type: 'string'
})
}).argv
add
and rm
subcommands should expect some number of arguments?
add
or rm
should be specified?
required: true
probably
add
or rm
.demandCommand
git remote rename <old> <new>
git remote remove <name>
Hi guys,
I have a problem no other command line parsing library I've explored (probably) supports and since the generality of yargs, maybe you have some solution for it, but I can't really tell as from many options you provide, I'm a bit lost :).
I want to get a list of possibly multiple commands with arguments in a row as defined on the command line, so that I can build from it a "functional pipeline", that will be applied to some array/iterator/stream.
Is this case somehow solvable with yargs?
Many thanks...
Had a quick question. I am building a CLI using yargs and want to give users the options to add their own commands in a specific folder. I know I can use the following to accomplish this:
.commandDir(path.join(process.cwd(), 'commands))
This works great when the folder exists in the project, but if it does exist I get the following error:
Error: Error: ENOENT: no such file or directory, scandir 'DIRECTORY_PATH'
is there a way add the command directory ONLY if the directory exists?
yargs
supports command lines as the following: myprog -r repo -v clone -p proj -a
, i.e. having arguments (-r
, -v
) that are available for each command and are specified before it and arguments that are only valid for a specific command (-p
, -a
). Similar to https://git-scm.com/docs/git. I tried using something like yargs.option(...).command(...)
but that did not seem to work.
https://raw.githubusercontent.com/yargs/yargs/v15.4.1/docs/api.md
returns 404 for me
yargs
, that is really easy to use, supports subCommands (which is one of the thing why a lot of people use yargs), and it was intended to be testable by default.issue
why