Tweaks (#53)
* Fix loglevel parsing * Bump dependencies * Change --filter to --target * Update documentation * Import log handler as "loghandler" * Change command color to purple * Change flag name to target * Update formatting
This commit is contained in:
@@ -62,5 +62,11 @@ func initConfig() {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
}
|
||||
log.SetLevelFromString(viper.GetString("loglevel"))
|
||||
lvl, err := log.ParseLevel(viper.GetString("loglevel"))
|
||||
if err != nil {
|
||||
log.Fatalf("Couldn't parse log level: %s", err)
|
||||
return
|
||||
}
|
||||
log.SetLevel(lvl)
|
||||
|
||||
}
|
||||
|
||||
13
cmd/run.go
13
cmd/run.go
@@ -15,7 +15,7 @@ import (
|
||||
var runCmd = &cobra.Command{
|
||||
Use: "run <command to run>",
|
||||
Short: "Run command on remote servers",
|
||||
Example: " speedrun run whoami\n speedrun run whoami --only-failures --filter \"labels.foo = bar AND labels.environment = staging\"",
|
||||
Example: " speedrun run whoami\n speedrun run whoami --only-failures --target \"labels.foo = bar AND labels.environment = staging\"",
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
initConfig()
|
||||
@@ -24,7 +24,7 @@ var runCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
func init() {
|
||||
runCmd.Flags().String("filter", "", "Fetch instances that match the filter")
|
||||
runCmd.Flags().StringP("target", "t", "", "Fetch instances that match the target selection criteria")
|
||||
runCmd.Flags().String("projectid", "", "Override GCP project id")
|
||||
runCmd.Flags().Bool("only-failures", false, "Print only failures and errors")
|
||||
runCmd.Flags().Bool("ignore-fingerprint", false, "Ignore host's fingerprint mismatch")
|
||||
@@ -39,7 +39,6 @@ func init() {
|
||||
viper.BindPFlag("ssh.only-failures", runCmd.Flags().Lookup("only-failures"))
|
||||
viper.BindPFlag("ssh.concurrency", runCmd.Flags().Lookup("concurrency"))
|
||||
viper.BindPFlag("ssh.use-private-ip", runCmd.Flags().Lookup("use-private-ip"))
|
||||
|
||||
}
|
||||
|
||||
func run(cmd *cobra.Command, args []string) error {
|
||||
@@ -52,7 +51,7 @@ func run(cmd *cobra.Command, args []string) error {
|
||||
usePrivateIP := viper.GetBool("ssh.use-private-ip")
|
||||
useOSlogin := viper.GetBool("gcp.use-oslogin")
|
||||
|
||||
filter, err := cmd.Flags().GetString("filter")
|
||||
target, err := cmd.Flags().GetString("target")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -72,8 +71,8 @@ func run(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Info("Fetching list of GCE instances")
|
||||
instances, err := gcpClient.GetInstances(filter, usePrivateIP)
|
||||
log.Info("Fetching instance list")
|
||||
instances, err := gcpClient.GetInstances(target, usePrivateIP)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -94,7 +93,7 @@ func run(cmd *cobra.Command, args []string) error {
|
||||
m := marathon.New(command, timeout, concurrency)
|
||||
err = m.Run(instances, k, ignoreFingerprint)
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
m.PrintResult(onlyFailures)
|
||||
|
||||
Reference in New Issue
Block a user