Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

methodology for creating top level actions à la Dockêr #36

Open
ORESoftware opened this issue Jul 1, 2017 · 2 comments
Open

methodology for creating top level actions à la Dockêr #36

ORESoftware opened this issue Jul 1, 2017 · 2 comments

Comments

@ORESoftware
Copy link
Contributor

ORESoftware commented Jul 1, 2017

With docker in mind, we have a command line API like so:

docker run
docker build
docker ps

or with Istanbul in mind:

istanbul cover
istanbul report
istanbul instrument

or git:

git merge
git rebase
git checkout

etc.

is there a methodology for creating this kind of top-level action api with dashdash?

AFAICT, you'd have to make a homegrown system from dashdash, and from what I can tell, you'd have to enforce that the first argument after docker was the action.

Right now, I have a CLI API using dashdash, but it's more akin to:

docker --run
docker --cp
docker --ps
docker --create
docker --images

where the actions are all just booleans according my dashdash config.

Just something to discuss.

I think it would be a neat feature if dashdash could take an initialization argument to interpret the first x _args as actions. And these would be stored as a separate property on opts.

So it would be something like this:

const dashdash = require('dashdash');

let opts, parser = dashdash.createParser({options: options}, {
   actions: 1  // => the first arg is interpreted as an action, and it has to appear before any options 
});

try {
  opts = parser.parse(process.argv);
} catch (err) {
 // 
}

// opts => {};
// opts._args => []
// opts._actions => [] 
@ORESoftware ORESoftware changed the title methodology for creating top level actions methodology for creating top level actions à la Dockêr Jul 1, 2017
@ORESoftware
Copy link
Contributor Author

ORESoftware commented Sep 5, 2018

We can easily use a shell script to do this:

first_arg="$1";
shift 1;

if [ "$first_arg" == "merge" ]; then

  "$root/merge" "$@"

elif [  "$first_arg" == "rebase"  ]; then

  "$root/rebase" "$@"

elif [  "$first_arg" == "checkout"  ]; then

  "$root/checkout" "$@"

else 
   echo "whatevs"
fi

I have a nice way of using different dashdash options for each action/subcommand, which is probably the right way to do it.

my only remaining question/problem is how to get bash completion for git/docker style actions/subcommands

@trentm do you know how to get bash completion using dashdash, the way you can get bash completion for git subcommands? when I type in git me and then hit tab, I get git merge, that's what I mean. With dashdash, I can only get completion for something like git --merge.

@karfau
Copy link

karfau commented Jan 31, 2020

@ORESoftware did you check what https://github.com/trentm/node-cmdln offers?

On the first glance it sounds like what you are looking for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants