Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Benjamin E. Coe
    @bcoe
    @zyrolasting thanks for the report, any chance I could bother you to switch to the slack?
    It's a better place for me to coordinate work (mainly because I'm in there)
    Kalman Keri
    @kkeri
    Hi,
    how can I get yargs help to display another name instead of $0? $0 is cli.js but users will call the program by the name jsondl.
    So, for example I'd like to see jsondl <command> instead of cli.js <command>.
    David Mills
    @dvmlls
    @kkeri this is what i did
      const parser = yargs()
        .commandDir('./yargs-modules')
        .demandCommand(1, 'some help text')
        .wrap(null)
        .help()
        .strict();
    
      /* override the name of the running program argv[1] */
    parser.$0 = 'jsondl';
    
    parser.parse(someText);
    Kalman Keri
    @kkeri
    @dvmlls this works for me too, thanks! I even omitted someText.
    Noam Gal
    @ATGardner
    Hello.
    I am trying to use yargs to validate arguments sent in a POST request. I use yargs.config(req.body).argv to read the input and make sure all the required fields are there, before I perform my BI.
    I might be missing something basic and fundamental, but the 2nd POST request I get only adds anotehr 'layer' of parameters, instead of replacing it. I tried calling yargs.reset(), but it doesn't seem to do what I expected it would.
    Is there some other way to use yargs for my purpose? or maybe it's not a good use case for the library?
    Daniel Wang
    @ddwang
    Hi, a dumb question -- we've been using yargs with great success for a couple of years. Recently we updated one project from yargs 8 to jargs 11... everything works except the command hangs at the very end
    basically the process does not seem to exit after finishing all the work. any idea why this maybe?
    Daniel Wang
    @ddwang
    fwiw, found the problem. it wasn't yargs, but a sub-command using noble
    Lucas Bugnazet
    @Lucbug
    Hey all,
    I'm working with yargs to pass arguments in a gulp command. I am having troubles checking the validity of the arguments and what shall happen if the flag is present or not.
    Has anyone had experience with that ?
    Lucas Bugnazet
    @Lucbug
    Especially, I'm struggling to have the demandOption helper displaying
    Hugo Dias
    @hugomrdias
    hi guys do you know how can i get parsed argv inside .fail method?
    Nicholas H.
    @ukaaa

    Is there a way to parse argv and turn them into an array of options in the shape of argv._?
    So when I have

    // argv
    {
      _: [],
      foo: 'bar'
    }

    Turn it into

    // parsed
    ['--foo', 'bar']
    I would like to do this to get specific options out of the arguments, but pass the remaining ones to a child process using cross-spawn
    Edgar Pan
    @edgaryp
    hey gusy, I ran npm uninstall yargs --save-dev and npm uninstall yargs but still see yargs in node_modules folder? My npm is version 5.6.0.
    Mateusz Burzyński
    @Andarist
    is it possible to specify default command with variadic list of arguments?
    I'm trying various forms of array, type: array etc but cant make it work
    i'd like my script to be usable as
    my_script input input2 input3 --other option
    Mateusz Burzyński
    @Andarist
    found it in tests :see_no_evil:
    $0 [input..] does the trick
    Sean Dietrich
    @sean-e-dietrich
    I am fairly new to Yargs but wanted to know if it was possible to prefix commands with global arguments. So when running the command it would apply to any and all commands
    script-name global-arg command --option=1
    Benjamin E. Coe
    @bcoe
    :wave: hey @sean-e-dietrich, just an FYI; we're using Slack for chat now, happy to field your questions here: http://devtoolscommunity.herokuapp.com/
    Iliyan Peychev
    @ipeychev
    Hello, I have a question regarding sub-commands. I would like to have a command called 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
    How can I specify that add and rm subcommands should expect some number of arguments?
    how can I tell yargs that at least add or rm should be specified?
    is there somewhere an example?
    Jordan Harband
    @ljharb
    demandOption?
    or required: true probably
    Iliyan Peychev
    @ipeychev
    but I want only one to be required at time, not both
    either add or rm
    Jordan Harband
    @ljharb
    i think you want to then have two commands - remote add and remote rm
    and then .demandCommand
    Iliyan Peychev
    @ipeychev
    hm, so to create two commans, called remote add and remote rm? Doesn't yargs support kinda sub-commands?
    I thought "positionals" are the closest one to this concept
    Jordan Harband
    @ljharb
    i'm not sure how to require only one of those two tho, as subcommands
    Iliyan Peychev
    @ipeychev
    hm, I can't believe this is not possible with yargs. A good example would be git remote --help - there are many sub-commands plus additional params for each of them
    this is what I want to achieve
    like:
    git remote rename <old> <new>
    git remote remove <name>
    Jordan Harband
    @ljharb
    i mean that is in the examples
    Iliyan Peychev
    @ipeychev
    interesting, I'll check this. this thing with merging separate files I'm not sure I like very much on first sight (I hate magic), but I'll try to see of I'll build something based on that
    thanks!
    Míla Kuchta
    @kuchta

    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...

    Syed Faraaz Ahmad
    @faraazahmad
    what does the nargs() function do?
    I looked at the docs, and I dont understand it
    an example or 2 would be really helplful
    ClimbFlyCamp
    @ClimbFlyCamp

    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?

    Joel Kirchartz
    @JKirchartz
    hey, I'm trying to use commandDir here in /bin to load commands from /lib but it seems the positional arguments only work for the first command and not the other ones? am I doing something wrong? https://github.com/jkirchartz/pos2tracery