mirror of
https://github.com/containers/skopeo.git
synced 2025-09-20 01:20:09 +00:00
Create a globalOptions structure
This works just like the command-specific options. Also moves the "Before:" handler into a separate method. Does not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
This commit is contained in:
@@ -15,8 +15,13 @@ import (
|
|||||||
// and will be populated by the Makefile
|
// and will be populated by the Makefile
|
||||||
var gitCommit = ""
|
var gitCommit = ""
|
||||||
|
|
||||||
|
type globalOptions struct {
|
||||||
|
}
|
||||||
|
|
||||||
// createApp returns a cli.App to be run or tested.
|
// createApp returns a cli.App to be run or tested.
|
||||||
func createApp() *cli.App {
|
func createApp() *cli.App {
|
||||||
|
opts := globalOptions{}
|
||||||
|
|
||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
app.EnableBashCompletion = true
|
app.EnableBashCompletion = true
|
||||||
app.Name = "skopeo"
|
app.Name = "skopeo"
|
||||||
@@ -65,15 +70,7 @@ func createApp() *cli.App {
|
|||||||
Usage: "timeout for the command execution",
|
Usage: "timeout for the command execution",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
app.Before = func(c *cli.Context) error {
|
app.Before = opts.before
|
||||||
if c.GlobalBool("debug") {
|
|
||||||
logrus.SetLevel(logrus.DebugLevel)
|
|
||||||
}
|
|
||||||
if c.GlobalIsSet("tls-verify") {
|
|
||||||
logrus.Warn("'--tls-verify' is deprecated, please set this on the specific subcommand")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
app.Commands = []cli.Command{
|
app.Commands = []cli.Command{
|
||||||
copyCmd(),
|
copyCmd(),
|
||||||
inspectCmd(),
|
inspectCmd(),
|
||||||
@@ -87,6 +84,17 @@ func createApp() *cli.App {
|
|||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// before is run by the cli package for any command, before running the command-specific handler.
|
||||||
|
func (opts *globalOptions) before(c *cli.Context) error {
|
||||||
|
if c.GlobalBool("debug") {
|
||||||
|
logrus.SetLevel(logrus.DebugLevel)
|
||||||
|
}
|
||||||
|
if c.GlobalIsSet("tls-verify") {
|
||||||
|
logrus.Warn("'--tls-verify' is deprecated, please set this on the specific subcommand")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if reexec.Init() {
|
if reexec.Init() {
|
||||||
return
|
return
|
||||||
|
Reference in New Issue
Block a user