github.com/nak3/source-to-image@v1.1.10-0.20180319140719-2ed55639898d/pkg/cmd/cli/util/util.go (about)

     1  package cmd
     2  
     3  import (
     4  	"flag"
     5  	"os"
     6  	"path/filepath"
     7  
     8  	log "github.com/golang/glog"
     9  
    10  	"github.com/openshift/source-to-image/pkg/api"
    11  	"github.com/spf13/cobra"
    12  	"github.com/spf13/pflag"
    13  )
    14  
    15  // AddCommonFlags adds the common flags for usage, build and rebuild commands
    16  func AddCommonFlags(c *cobra.Command, cfg *api.Config) {
    17  	c.Flags().BoolVarP(&(cfg.Quiet), "quiet", "q", false,
    18  		"Operate quietly. Suppress all non-error output.")
    19  	c.Flags().BoolVar(&(cfg.Incremental), "incremental", false,
    20  		"Perform an incremental build")
    21  	c.Flags().BoolVar(&(cfg.RemovePreviousImage), "rm", false,
    22  		"Remove the previous image during incremental builds")
    23  	c.Flags().StringVar(&(cfg.CallbackURL), "callback-url", "",
    24  		"Specify a URL to invoke via HTTP POST upon build completion")
    25  	c.Flags().VarP(&(cfg.BuilderPullPolicy), "pull-policy", "p",
    26  		"Specify when to pull the builder image (always, never or if-not-present)")
    27  	c.Flags().Var(&(cfg.PreviousImagePullPolicy), "incremental-pull-policy",
    28  		"Specify when to pull the previous image for incremental builds (always, never or if-not-present)")
    29  	c.Flags().Var(&(cfg.RuntimeImagePullPolicy), "runtime-pull-policy",
    30  		"Specify when to pull the runtime image (always, never or if-not-present)")
    31  	c.Flags().BoolVar(&(cfg.PreserveWorkingDir), "save-temp-dir", false,
    32  		"Save the temporary directory used by S2I instead of deleting it")
    33  	c.Flags().StringVarP(&(cfg.DockerCfgPath), "dockercfg-path", "", filepath.Join(os.Getenv("HOME"), ".docker/config.json"),
    34  		"Specify the path to the Docker configuration file")
    35  	c.Flags().StringVarP(&(cfg.Destination), "destination", "d", "",
    36  		"Specify a destination location for untar operation")
    37  }
    38  
    39  // SetupGlog makes --loglevel reflect in glog's -v flag
    40  func SetupGlog(flags *pflag.FlagSet) {
    41  
    42  	from := flag.CommandLine
    43  	if fflag := from.Lookup("v"); fflag != nil {
    44  		level := fflag.Value.(*log.Level)
    45  		loglevelPtr := (*int32)(level)
    46  		flags.Int32Var(loglevelPtr, "loglevel", 0, "Set the level of log output (0-5)")
    47  	}
    48  
    49  	// FIXME currently glog has only option to redirect output to stderr
    50  	// the preferred for S2I would be to redirect to stdout
    51  	flag.CommandLine.Set("logtostderr", "true")
    52  }