[lxc-devel] [lxd/master] Fix some more command line parsing issues

stgraber on Github lxc-bot at linuxcontainers.org
Wed Apr 4 16:55:45 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180404/b68a3de7/attachment.bin>
-------------- next part --------------
From 7a8590465f09dce3f5844896447f6743cf56c57f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 4 Apr 2018 12:43:43 -0400
Subject: [PATCH 1/2] lxc/query: Fix -d and -X
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #4406

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxc/main.go          | 2 +-
 lxc/query.go         | 4 ++--
 test/main.sh         | 1 +
 test/suites/query.sh | 9 +++++++++
 4 files changed, 13 insertions(+), 3 deletions(-)
 create mode 100644 test/suites/query.sh

diff --git a/lxc/main.go b/lxc/main.go
index 70abc6817..f558e479d 100644
--- a/lxc/main.go
+++ b/lxc/main.go
@@ -55,7 +55,7 @@ For help with any of those, simply call them with --help.`))
 	app.PersistentFlags().BoolVar(&globalCmd.flagVersion, "version", false, i18n.G("Print version number"))
 	app.PersistentFlags().BoolVarP(&globalCmd.flagHelp, "help", "h", false, i18n.G("Print help"))
 	app.PersistentFlags().BoolVar(&globalCmd.flagForceLocal, "force-local", false, i18n.G("Force using the local unix socket"))
-	app.PersistentFlags().BoolVarP(&globalCmd.flagLogDebug, "debug", "d", false, i18n.G("Show all debug messages"))
+	app.PersistentFlags().BoolVar(&globalCmd.flagLogDebug, "debug", false, i18n.G("Show all debug messages"))
 	app.PersistentFlags().BoolVarP(&globalCmd.flagLogVerbose, "verbose", "v", false, i18n.G("Show all information messages"))
 
 	// Local flags
diff --git a/lxc/query.go b/lxc/query.go
index 39881d470..1c8efc755 100644
--- a/lxc/query.go
+++ b/lxc/query.go
@@ -34,8 +34,8 @@ func (c *cmdQuery) Command() *cobra.Command {
 	cmd.RunE = c.Run
 	cmd.Flags().BoolVar(&c.flagRespWait, "wait", false, i18n.G("Wait for the operation to complete"))
 	cmd.Flags().BoolVar(&c.flagRespRaw, "raw", false, i18n.G("Print the raw response"))
-	cmd.Flags().StringVar(&c.flagAction, "X", "GET", i18n.G("Action (defaults to GET)")+"``")
-	cmd.Flags().StringVar(&c.flagData, "d", "", i18n.G("Input data")+"``")
+	cmd.Flags().StringVarP(&c.flagAction, "request", "X", "GET", i18n.G("Action (defaults to GET)")+"``")
+	cmd.Flags().StringVarP(&c.flagData, "data", "d", "", i18n.G("Input data")+"``")
 
 	return cmd
 }
diff --git a/test/main.sh b/test/main.sh
index cd57cb498..be52c3b9e 100755
--- a/test/main.sh
+++ b/test/main.sh
@@ -196,6 +196,7 @@ run_test test_resources "resources"
 run_test test_kernel_limits "kernel limits"
 run_test test_macaroon_auth "macaroon authentication"
 run_test test_console "console"
+run_test test_query "query"
 run_test test_proxy_device "proxy device"
 run_test test_storage_local_volume_handling "storage local volume handling"
 run_test test_clustering_membership "clustering membership"
diff --git a/test/suites/query.sh b/test/suites/query.sh
new file mode 100644
index 000000000..84bfee8b7
--- /dev/null
+++ b/test/suites/query.sh
@@ -0,0 +1,9 @@
+test_query() {
+  ensure_import_testimage
+  ensure_has_localhost_remote "${LXD_ADDR}"
+
+  lxc init testimage querytest
+  lxc query --wait -X POST -d "{\\\"name\\\": \\\"snap-test\\\"}" /1.0/containers/querytest/snapshots
+  lxc info querytest | grep snap-test
+  lxc delete querytest
+}

From f14285a1f1ca5c74390b9867aafc272fd45b42e5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 4 Apr 2018 12:54:58 -0400
Subject: [PATCH 2/2] lxc/help: Make help respect --all too
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #4406

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxc/main.go | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/lxc/main.go b/lxc/main.go
index f558e479d..9bda930f1 100644
--- a/lxc/main.go
+++ b/lxc/main.go
@@ -58,9 +58,6 @@ For help with any of those, simply call them with --help.`))
 	app.PersistentFlags().BoolVar(&globalCmd.flagLogDebug, "debug", false, i18n.G("Show all debug messages"))
 	app.PersistentFlags().BoolVarP(&globalCmd.flagLogVerbose, "verbose", "v", false, i18n.G("Show all information messages"))
 
-	// Local flags
-	app.Flags().BoolVar(&globalCmd.flagHelpAll, "all", false, i18n.G("Show less common commands"))
-
 	// Wrappers
 	app.PersistentPreRunE = globalCmd.PreRun
 	app.PersistentPostRunE = globalCmd.PostRun
@@ -193,6 +190,20 @@ For help with any of those, simply call them with --help.`))
 	versionCmd := cmdVersion{global: &globalCmd}
 	app.AddCommand(versionCmd.Command())
 
+	// Get help command
+	app.InitDefaultHelpCmd()
+	var help *cobra.Command
+	for _, cmd := range app.Commands() {
+		if cmd.Name() == "help" {
+			help = cmd
+			break
+		}
+	}
+
+	// Help flags
+	app.Flags().BoolVar(&globalCmd.flagHelpAll, "all", false, i18n.G("Show less common commands"))
+	help.Flags().BoolVar(&globalCmd.flagHelpAll, "all", false, i18n.G("Show less common commands"))
+
 	// Deal with --all flag
 	err := app.ParseFlags(os.Args[1:])
 	if err == nil {


More information about the lxc-devel mailing list