Coder Social home page Coder Social logo

Comments (11)

DannyBen avatar DannyBen commented on September 22, 2024

This was raised in #258, implemented in #271, and available in bashly v0.8.7.

See this documentation section and the docker-like example.

Is this what you need?

Also - if you want to just have similar flags in several commands, you do not need to use import - you can use YAML anchors:

commands:
- name: upload
  flags:
  - &fprce
    long: --force
    short: -f
    help: Force something

  - &debug
    long: --debug
    short: -d
    help: Debug something

- name: delete
  flags:
  - *force
  - *debug

  - long: --query
    help: Other flags

from bashly.

DannyBen avatar DannyBen commented on September 22, 2024

I have added a Reusable Flags Example - in case this is the pattern you were looking for.

from bashly.

niksfirefly avatar niksfirefly commented on September 22, 2024

Well It is fine for me
but I think
It would be better to set common flags and ENVs in additional top bashly.yml section
named global: or common:
for sake of clarity

regards

from bashly.

DannyBen avatar DannyBen commented on September 22, 2024

I thought about it, and decided against, since the root config is the same as command config, and there is no way that both "flags" and "global_flags" will exist - its only one.

  • If a command has both flags and commands - it means the flags are global, and will be available to all commands
  • If a command has only commands, each command may have its own flags
  • If a command has only flags (and maybe args) it is used by the command itself.

I think it works.
Generally speaking, I feel that having global flags before the command is bad form. I would recommend anyone to try and avoid using this at all, and instead, define the needed flags directly in the command(s) that need them - but, since there was some demand, I enabled this option as well.

from bashly.

niksfirefly avatar niksfirefly commented on September 22, 2024

Well there is already global flag --help
so I think there could be more of them

from bashly.

DannyBen avatar DannyBen commented on September 22, 2024

I am not following. You can create more global flags by using the method I outlined above.

The --debug flag in this example is going to be "global".

And to clarify: --help is not a global flag. It is a flag that is available on all commands, including the "root" command. It is different.

from bashly.

niksfirefly avatar niksfirefly commented on September 22, 2024

OK i rewrite your example from a few comments ago

common:
  flags:
  - force
    long: --force
    short: -f
    help: Force something

  - debug
    long: --debug
    short: -d
    help: Debug something

commands:
- name: upload
  flags:
    long: --some_upload_flag
    help: Other flags

- name: delete
  flags:
  - long: --query
    help: Other flags

This way every command gets force and debug flags

$ cli upload arg --some_upload_flag --force --debug
$ cli delete arg --query --force --debug

common section is descriptive and in bashly spirit
Of course that's my 2 cents

from bashly.

DannyBen avatar DannyBen commented on September 22, 2024

Ok - this is not bad actually. So we are talking about common flags and not global flags.

It is a good idea, I need to think about it.

The primary concern I have with it, is that it adds yet another way of sharing flags or other definitions between commands. There are several already, and I am afraid of confusing users.

What else other than flags do you expect to find in the common section?

from bashly.

DannyBen avatar DannyBen commented on September 22, 2024

After reviewing, I have decided to not implement this for the time being.

Using global flags or reusable flags can be easily achieved with one of the methods I mentioned above, and adding another configuration construct like this will complicate things (like deeply nested commands) and just add more edge cases that need to be take care of.

Nonetheless, thanks for the suggestion - I hope your use case can employ one of the methods already available.

from bashly.

niksfirefly avatar niksfirefly commented on September 22, 2024

Well I think there are some useful common flags that works on any commands and any level of application
for example --help --verbose --debug --version --dry-run --logging etc.
so such section as common: could be only improvement and easily understood by everyone.
In my opinion - better than native yaml solutions,
but It is of course your decision.
regards and thx for good work :)

from bashly.

DannyBen avatar DannyBen commented on September 22, 2024

You did notice that I provided another solution other than the YAML aliases right?

See this documentation section and the docker-like example.

from bashly.

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.