Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    firecyberice
    @firecyberice
    This message was deleted
    Timo Reimann
    @timoreimann

    hi there! I'm just starting to use Cobra and wonder if there are any best practices regarding (unit-)testing my CLI application?

    example projects with good testing approaches would be greatly appreciated too. thanks!

    Bjørn Erik Pedersen
    @bep
    Test your UNITS not the CLI ... Which means the Cobra funcs must be short with no real logic.
    Timo Reimann
    @timoreimann
    @bep that sounds reasonable, thanks. I'm thinking though that a certain (fairly little) amount of (integration) testing should run through Corba functions to ensure that the wiring works properly. Any thoughts on this one?
    Bjørn Erik Pedersen
    @bep
    I think you will find most projects are fairly pragmatic about their commands, but have a look at the big Cobra projects, Kubernetes etc. for inspiration.
    Christopher
    @CharlesBlack89
    Hi Folks o/ I'm trying to invoke the Help() function from within a subcommand when a user doesn't pass enough arguments rather than a generic error message. Something like:
    var addCmd = &cobra.Command{ Use: "add", Short: "Add a new (offline) ESXI VM to the DB", Run: func(cmd *cobra.Command, args []string) error { if (len(args) == 0) { addCmd.Help() } } }
    Currently I'm seeing: undefined: addCmd in addCmd.Help
    Any thoughts/input/guidance would be most appreciated. Thx in advance.
    Cameron Moore
    @moorereason
    @CharlesBlack89, you can't reference addCmd here b/c it doesn't exist yet. Maybe cmd.Help()?
    Christopher
    @CharlesBlack89
    @moorereason cmd.Help() does the trick ~ I figured it out yesterday shortly after posting here and :faceplam:
    MattC
    @devcott_twitter
    Is there a way of declaring arguments in with Cobra. I don't mean flags or commands. I have a command e.g. "myCli read someAppName". read is a command. someAppName is an arguments. I want the CLI help to show the requirement for an argument.
    I want it to show the usage info when a user enters "myCli read" without an app name arg.
    Fjolnir-Dvorak
    @Fjolnir-Dvorak
    If yes, could someone be so kind to add that to the readme.md examples? I found a few tickets about that but I have still no idea if it is possible for subcommands and rootcommand and how, and if not for rootcommand, why.
    Fjolnir-Dvorak
    @Fjolnir-Dvorak
    What exactly is the problem with $home in darwin? Is cgo not avaiable there or is anything broken with that?
    Fjolnir-Dvorak
    @Fjolnir-Dvorak
    is there someone who is using Cobra in a multi-language project?
    James Albert
    @jamesalbert
    anyone still in here?
    Frederick F. Kautz IV
    @fkautz
    Yes :)
    James Albert
    @jamesalbert
    nice! :D I'm just wondering if there's a way to call cobra commands from another project. Something like
    cmd := user.SomeCmd()
    subcmd, args, err := cmd.Traverse([]string{"some-subcommand"})
    if err != nil {
      return
    }
    ret := cmd.Execute()
    where user.SomeCmd returns a cobra.command
    It's sort of working, but I'm not sure how to pass flags
    Frederick F. Kautz IV
    @fkautz
    Give me a few moments and I'll take a look, grabbing a coffee at philz
    James Albert
    @jamesalbert
    and I'm not sure if this is the right way to do it. np no rush
    Frederick F. Kautz IV
    @fkautz
    it's been a while since i've worked with cobra itself, but maybe i can give an example that will help
    i've got a set of config structs listed here:
    and some commands that populate that config listed here
    one thing i added in was RootCmd.AddCommand(serveCmd)
    which lets me built up the tree
    James Albert
    @jamesalbert
    I see, I probably just need to export my config structs for the most part
    Frederick F. Kautz IV
    @fkautz
    i think you may be able to use AddCommand to insert commands from other projects in
    James Albert
    @jamesalbert
    Okay, that makes more sense
    Frederick F. Kautz IV
    @fkautz
    anyways, i'm not a cobra author :p but hoping this helps
    i don't see a reason why it wouldn't work
    the reason i exposed the config file out as well was because i wanted to parse them from a config file
    James Albert
    @jamesalbert
    thanks a lot, much appreciated. I usually don't get much from gitter :D
    Yeah, that's probably the key right there
    Frederick F. Kautz IV
    @fkautz
    no problem, just luck today, i was on pinging a friend of mine from one of the few projects i'm aware of that are active on gitter
    spacemacs if you're interested
    it's an emacs distribution which happens to have a high quality vim-keybindings plugin
    anyways, saw this and thought i could help :p
    James Albert
    @jamesalbert
    Nice, I'll check it out. I mostly use vim and funny enough I'm rocking spf13's vim dist
    Frederick F. Kautz IV
    @fkautz
    yea, his distro is good
    Stanton
    @stantonxu
    @spf13 , how to determine if my Cobra commands are executed in interactive shell or are called by script?
    any hints?
    I considered to run command echo $-, and later realized it won’t work. as long as I execute it, it will show me that it is non-interactive, so I cannot use this command to decide.
    Fjolnir-Dvorak
    @Fjolnir-Dvorak
    I have a question about the go latest circleCI test in this pull request: spf13/cobra#485
    I am working on go 1.11 and local tests are passing. I do not really understand what the circleCI test is doing. Is there anything I can look up on how those tests are working?
    Alexandre Picard-Lemieux
    @piclemx
    someone still there?
    Jean-Marcel Belmont
    @jbelmont
    image.png