[lxc-devel] [lxd/master] Improve pause help

tych0 on Github lxc-bot at linuxcontainers.org
Wed Jul 6 22:28:04 UTC 2016


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/20160706/276a2c97/attachment.bin>
-------------- next part --------------
From dd70184330e3e70bab36363bfe40177ce5b7d56f Mon Sep 17 00:00:00 2001
From: Tycho Andersen <tycho.andersen at canonical.com>
Date: Wed, 6 Jul 2016 15:35:51 -0600
Subject: [PATCH 1/2] use named args for actionCmds

We'll take advantage of this in the next patch making the diff much
shorter.

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 lxc/main.go | 55 +++++++++++++++++++++++++++++++++++++------------------
 1 file changed, 37 insertions(+), 18 deletions(-)

diff --git a/lxc/main.go b/lxc/main.go
index ff8b085..fc2da81 100644
--- a/lxc/main.go
+++ b/lxc/main.go
@@ -155,29 +155,48 @@ type command interface {
 }
 
 var commands = map[string]command{
-	"config":   &configCmd{},
-	"copy":     &copyCmd{},
-	"delete":   &deleteCmd{},
-	"exec":     &execCmd{},
-	"file":     &fileCmd{},
-	"finger":   &fingerCmd{},
-	"help":     &helpCmd{},
-	"image":    &imageCmd{},
-	"info":     &infoCmd{},
-	"init":     &initCmd{},
-	"launch":   &launchCmd{},
-	"list":     &listCmd{},
-	"monitor":  &monitorCmd{},
-	"move":     &moveCmd{},
-	"pause":    &actionCmd{shared.Freeze, false, false, "pause", -1, false, false, false},
+	"config":  &configCmd{},
+	"copy":    &copyCmd{},
+	"delete":  &deleteCmd{},
+	"exec":    &execCmd{},
+	"file":    &fileCmd{},
+	"finger":  &fingerCmd{},
+	"help":    &helpCmd{},
+	"image":   &imageCmd{},
+	"info":    &infoCmd{},
+	"init":    &initCmd{},
+	"launch":  &launchCmd{},
+	"list":    &listCmd{},
+	"monitor": &monitorCmd{},
+	"move":    &moveCmd{},
+	"pause": &actionCmd{
+		action:  shared.Freeze,
+		name:    "pause",
+	},
 	"profile":  &profileCmd{},
 	"publish":  &publishCmd{},
 	"remote":   &remoteCmd{},
-	"restart":  &actionCmd{shared.Restart, true, true, "restart", -1, false, false, false},
+	"restart":  &actionCmd{
+		action: shared.Restart,
+		hasTimeout: true,
+		visible: true,
+		name: "restart",
+		timeout: -1,
+	},
 	"restore":  &restoreCmd{},
 	"snapshot": &snapshotCmd{},
-	"start":    &actionCmd{shared.Start, false, true, "start", -1, false, false, false},
-	"stop":     &actionCmd{shared.Stop, true, true, "stop", -1, false, false, false},
+	"start":    &actionCmd{
+		action: shared.Start,
+		visible: true,
+		name: "start",
+	},
+	"stop":     &actionCmd{
+		action: shared.Stop,
+		hasTimeout: true,
+		visible: true,
+		name: "stop",
+		timeout: -1,
+	},
 	"version":  &versionCmd{},
 }
 

From 27ff38d0a670c867a59cf292d2ee241423ddbee7 Mon Sep 17 00:00:00 2001
From: Tycho Andersen <tycho.andersen at canonical.com>
Date: Wed, 6 Jul 2016 16:27:09 -0600
Subject: [PATCH 2/2] add some additional help to `lxc pause`

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 lxc/action.go | 23 ++++++++++++++---------
 lxc/main.go   | 39 ++++++++++++++++++++-------------------
 2 files changed, 34 insertions(+), 28 deletions(-)

diff --git a/lxc/action.go b/lxc/action.go
index 6858bc9..8fece38 100644
--- a/lxc/action.go
+++ b/lxc/action.go
@@ -10,14 +10,15 @@ import (
 )
 
 type actionCmd struct {
-	action     shared.ContainerAction
-	hasTimeout bool
-	visible    bool
-	name       string
-	timeout    int
-	force      bool
-	stateful   bool
-	stateless  bool
+	action         shared.ContainerAction
+	hasTimeout     bool
+	visible        bool
+	name           string
+	timeout        int
+	force          bool
+	stateful       bool
+	stateless      bool
+	additionalHelp string
 }
 
 func (c *actionCmd) showByDefault() bool {
@@ -25,10 +26,14 @@ func (c *actionCmd) showByDefault() bool {
 }
 
 func (c *actionCmd) usage() string {
+	if c.additionalHelp != "" {
+		c.additionalHelp = fmt.Sprintf("\n\n%s", c.additionalHelp)
+	}
+
 	return fmt.Sprintf(i18n.G(
 		`Changes state of one or more containers to %s.
 
-lxc %s <name> [<name>...]`), c.name, c.name)
+lxc %s <name> [<name>...]%s`), c.name, c.name, c.additionalHelp)
 }
 
 func (c *actionCmd) flags() {
diff --git a/lxc/main.go b/lxc/main.go
index fc2da81..4938a0f 100644
--- a/lxc/main.go
+++ b/lxc/main.go
@@ -170,34 +170,35 @@ var commands = map[string]command{
 	"monitor": &monitorCmd{},
 	"move":    &moveCmd{},
 	"pause": &actionCmd{
-		action:  shared.Freeze,
-		name:    "pause",
+		action:         shared.Freeze,
+		name:           "pause",
+		additionalHelp: i18n.G("The opposite of `lxc pause` is `lxc start`."),
 	},
-	"profile":  &profileCmd{},
-	"publish":  &publishCmd{},
-	"remote":   &remoteCmd{},
-	"restart":  &actionCmd{
-		action: shared.Restart,
+	"profile": &profileCmd{},
+	"publish": &publishCmd{},
+	"remote":  &remoteCmd{},
+	"restart": &actionCmd{
+		action:     shared.Restart,
 		hasTimeout: true,
-		visible: true,
-		name: "restart",
-		timeout: -1,
+		visible:    true,
+		name:       "restart",
+		timeout:    -1,
 	},
 	"restore":  &restoreCmd{},
 	"snapshot": &snapshotCmd{},
-	"start":    &actionCmd{
-		action: shared.Start,
+	"start": &actionCmd{
+		action:  shared.Start,
 		visible: true,
-		name: "start",
+		name:    "start",
 	},
-	"stop":     &actionCmd{
-		action: shared.Stop,
+	"stop": &actionCmd{
+		action:     shared.Stop,
 		hasTimeout: true,
-		visible: true,
-		name: "stop",
-		timeout: -1,
+		visible:    true,
+		name:       "stop",
+		timeout:    -1,
 	},
-	"version":  &versionCmd{},
+	"version": &versionCmd{},
 }
 
 // defaultAliases contains LXC's built-in command line aliases.  The built-in


More information about the lxc-devel mailing list