Git Product home page Git Product logo

Comments (4)

nexdrew avatar nexdrew commented on June 8, 2024 1

Yeah. I'll admit that your example is not something I've seen in a CLI before, and sywac is probably not a good choice for that use-case at the moment.

Thanks for reporting!

from sywac.

nexdrew avatar nexdrew commented on June 8, 2024

@elliot-nelson Hi - sorry I've been so AWOL on providing help with sywac!

My immediate thought would be to interpret -l as an array type (so it can hold multiple values) and then use the 1st element as the "look for" value and the 2nd element as the "update" value.

Otherwise, we might need to plug in a custom type for either the -l flag (to hold multiple values in a more suitable way) or for the command type (to override how "local" flags do or do not override "global" flags - which I'm not entirely sure is possible at the moment, but we could probably figure out something).

To plug in your own type, you can either use sywac.registerFactory(nameString, factoryFunction) or sywac.custom(typeInstance).

from sywac.

nexdrew avatar nexdrew commented on June 8, 2024

@elliot-nelson Here's a super naive/minimalistic example of what I was describing:

require('../sywac')
  .configure({ name: 'slalom' })
  .command('query', {
    setup: sywac => {
      sywac
        .array('-l')
        .string('-i')
        .command('update', {
          run: argv => {
            console.log(`look for ${argv.l[0]} in ${argv.i} and update to ${argv.l[1]}`)
          }
        })
    }
  })
  .showHelpByDefault()
  .parseAndExit()
$ node issue45.js query -l 'retired' -i '10.11.*' update -l 'Retired'
look for retired in 10.11.* and update to Retired

Does something like that make sense for your use-case?

from sywac.

elliot-nelson avatar elliot-nelson commented on June 8, 2024

Thanks for the example! That does make sense, but in reality I probably couldn't rely on it - because there are many fields that can be used as query, update, or both, the array would not always be 2 elements long.

For each field that is 1 element long, there's no way to tell whether the value is supposed to be a query or an update, because the params aren't actually attached to the command in any way.

(And maybe they shouldn't be - not every command line tool should be represented. Imagine trying to represent a CLI like ImageMagick for example - totally different paradigm.)

from sywac.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.