Cobra: Interactive mode?

Created on 24 Feb 2016  路  16Comments  路  Source: spf13/cobra

I was looking at Vorpal and thought this would be a cool feature for cobra. Or maybe it should be a separate library? (viper integration is tight!).

My particular use case is that I want to build a CLI app that stores some session-like information in memory and deletes the information after some period of inactivity but I'm not sure how I would accomplish this if the process ends in a normal cobra app.

Most helpful comment

Any news on this? Interactive shell library would be a great feature.

All 16 comments

I was just about to ask the same thing :)

However, I've been looking at the golang library like this one:

https://github.com/chzyer/readline

Any comment on the interactive CLI would be appreciated... For example if somebody was to do the integration would patches be accepted?

@ianwalter FWIW, if you're targeting linux I think you can accomplish this with shared memory as long as your processes don't unmap the memory on exit.

I think the feature is desirable. I've not given it enough thought to how it should be implemented or integrated.

A big requirement is that whatever solution used should be completely cross platform.
https://github.com/chzyer/readline seems like a good library to use for this.

What support in Cobra would you want that you don't have today by just importing the readline package?
Maybe something like what iShell is trying to do would help https://github.com/abiosoft/ishell

At the very least, adding examples to the readme would certainly be helpful.

It seems that CockroachDB uses both, but maybe not together.
https://github.com/cockroachdb/cockroach

These comments are helpful, thank you. I am going to close this while I investigate how the integration would work between Cobra and libraries like readline.

I can say as a golang novice that having a cobra library supporting interactive mode would definitely be a great feature and would make this project even better! I think that many developers would appreciate if cobra provided them with an API which would support this way of working.

As for the cross platform that feature would be nice but I don't think it should be mandatory at least not in the first round.

Any news on this? Interactive shell library would be a great feature.

This would be useful for asking the user for secrets (token/passwords) without compromising them. If used as a flag they will be saved in plaintext in the logs and if file/envar are used it would only be safe if the system isn't shared or public.

Question: in Cobra, is there a way to determine if it is executed in interactive shell or if it is called by scripts?

I do not believe cobra itself helps you here.

@eparis , do you have any suggestion how to do it?

thank you @lordnynex , will try it out

@lordnynex , I tried just now. It is actually not I am looking for.

I am looking for method to determine if my code is running in interactive mode or not. For example, if my code is running directly by "go run ...", interactive mode. If my code is called in some scripts, even if the scripts is running directly on terminal, I want it to tell me it is non-interactive mode as I want to use the default options for my code in that scenario.

Created feature request to the above code repository. Not sure if the author will look into it. Or do you have idea how to do it?

@stantonxu were you able to resolve this issue? I'm looking into a way of getting passwords without compromising them using cobra.

@vinuri unfortunately, not yet

@stantonxu what about https://github.com/manifoldco/promptui ?
claims that "It can be easily integrated into spf13/cobra, urfave/cli or any cli go application"

Was this page helpful?
0 / 5 - 0 ratings

Related issues

anentropic picture anentropic  路  4Comments

jjzcru picture jjzcru  路  3Comments

andygrunwald picture andygrunwald  路  6Comments

rogercoll picture rogercoll  路  5Comments

icholy picture icholy  路  6Comments