cobra

command module
v0.0.0-...-838b099 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2023 License: MIT Imports: 5 Imported by: 0

README

Configurations Loading using Viper and PFlag

An example of using the viper and cobra packages to build a cli program.

The program takes in environment variables, command, command arguments, and pflags with the following pattern.

ENV_NAME=ENV_VALUE APPNAME COMMAND ARG --PFLAG

Setup

  1. Build the program.

    $ make
    
  2. Run the program

    $ bin/cobra
    $ # Run the program with help subcommand, we get a help screen with the short descriptor of all commands and pflags.
    $ bin/cobra help
    
  3. Try out different arguments.

    $ bin/cobra -a localhost:7000 list -lr bucket/folder
    list args: bucket/folder
    Config: &{localhost:7000 admin password false true true}
    $ CY_ADDR=example.com:1234 bin/cobra list -lr bucket/folder
    list args: bucket/folder
    Config: &{example.com:1234 admin password false true true}
    $ CY_ADDR=example.com:1234 bin/cobra -a localhost:7000 list -lr bucket/folder
    list args: bucket/folder
    Config: &{localhost:7000 admin password false true true}
    

Reference and Credits

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL