Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Support Environment variables for CLI options
Browse files Browse the repository at this point in the history
  • Loading branch information
rashmigottipati committed Mar 1, 2017
1 parent 32a479f commit 0d41fe9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
6 changes: 6 additions & 0 deletions cmd/snaptel/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"strconv"
"text/tabwriter"

log "github.com/Sirupsen/logrus"
"github.com/intelsdi-x/snap/core/ctypes"
"github.com/urfave/cli"
)
Expand All @@ -40,6 +41,11 @@ type restAPIConfig struct {
}

func (c *config) loadConfig(path string) error {
log.WithFields(log.Fields{
"_module": "snaptel-config",
"_block": "loadConfig",
"config_path": path,
}).Warning("The snaptel configuration file will be deprecated. Find more information here: https://github.com/intelsdi-x/snap/issues/1539")
b, err := ioutil.ReadFile(path)
if err != nil {
return fmt.Errorf("Unable to read config. File might not exist.")
Expand Down
17 changes: 10 additions & 7 deletions cmd/snaptel/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,24 @@ var (
Value: "http://localhost:8181",
}
flAPIVer = cli.StringFlag{
Name: "api-version, a",
Usage: "The Snap API version",
Value: "v1",
Name: "api-version, a",
Usage: "The Snap API version",
EnvVar: "SNAP_API_VERSION",
Value: "v1",
}
flSecure = cli.BoolFlag{
Name: "insecure",
Usage: "Ignore certificate errors when Snap's API is running HTTPS",
Name: "insecure",
Usage: "Ignore certificate errors when Snap's API is running HTTPS",
EnvVar: "SNAP_INSECURE",
}
flRunning = cli.BoolFlag{
Name: "running",
Usage: "Shows running plugins",
}
flPassword = cli.BoolFlag{
Name: "password, p",
Usage: "Password for REST API authentication",
Name: "password, p",
Usage: "Require password for REST API authentication",
EnvVar: "SNAP_REST_PASSWORD",
}
flConfig = cli.StringFlag{
Name: "config, c",
Expand Down
6 changes: 3 additions & 3 deletions docs/SNAPTEL.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ $ snaptel [global options] command [command options] [arguments...]
### Global Options
```
--url, -u 'http://localhost:8181' Sets the URL to use [$SNAP_URL]
--insecure Ignore certificate errors when Snap's API is running HTTPS
--api-version, -a 'v1' The Snap API version
--password, -p Password for REST API authentication
--insecure Ignore certificate errors when Snap's API is running HTTPS [$SNAP_INSECURE]
--api-version, -a 'v1' The Snap API version [$SNAP_API_VERSION]
--password, -p Require password for REST API authentication [$SNAP_REST_PASSWORD]
--config, -c Path to a config file [$SNAPTEL_CONFIG_PATH]
--help, -h show help
--version, -v print the version
Expand Down

0 comments on commit 0d41fe9

Please sign in to comment.