[lxc-devel] [lxd/master] Add --man to client

stgraber on Github lxc-bot at linuxcontainers.org
Tue Aug 30 22:00:22 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/20160830/67535323/attachment.bin>
-------------- next part --------------
From ab48f3b9fd74f63d5510296b83120e2afcbd7668 Mon Sep 17 00:00:00 2001
From: Carlos Neira <cneirabustos at gmail.com>
Date: Fri, 26 Aug 2016 18:50:11 -0300
Subject: [PATCH 1/3] lxc: Add a manpage command

Closes #2280
Closes #2325

Signed-off-by: Carlos <cneirabustos at gmail.com>
---
 lxc/manpage.go | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
 create mode 100644 lxc/manpage.go

diff --git a/lxc/manpage.go b/lxc/manpage.go
new file mode 100644
index 0000000..8bc9b61
--- /dev/null
+++ b/lxc/manpage.go
@@ -0,0 +1,30 @@
+package main
+
+import (
+	"github.com/lxc/lxd"
+	"github.com/lxc/lxd/shared/i18n"
+)
+
+type manpageCmd struct{}
+
+func (c *manpageCmd) showByDefault() bool {
+	return false
+}
+
+func (c *manpageCmd) usage() string {
+	return i18n.G(
+		`Prints all subcommands help to create a lxd manpage`)
+}
+
+func (c *manpageCmd) flags() {
+}
+
+func (c *manpageCmd) run(_ *lxd.Config, args []string) error {
+	if len(args) > 0 {
+		return errArgs
+	}
+	for k, _ := range commands {
+		commands["help"].run(nil, []string{k})
+	}
+	return nil
+}

From 920aebc57db1c201e90bf435275ae52227a12439 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 30 Aug 2016 17:52:03 -0400
Subject: [PATCH 2/3] lxc: Add plumbing for --man
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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

diff --git a/lxc/main.go b/lxc/main.go
index 6b9a26c..22288e4 100644
--- a/lxc/main.go
+++ b/lxc/main.go
@@ -66,6 +66,10 @@ func run() error {
 		os.Args[1] = "version"
 	}
 
+	if len(os.Args) == 2 && os.Args[1] == "--man" {
+		os.Args[1] = "manpage"
+	}
+
 	if len(os.Args) < 2 {
 		commands["help"].run(nil, nil)
 		os.Exit(1)
@@ -167,6 +171,7 @@ var commands = map[string]command{
 	"init":    &initCmd{},
 	"launch":  &launchCmd{},
 	"list":    &listCmd{},
+	"manpage": &manpageCmd{},
 	"monitor": &monitorCmd{},
 	"move":    &moveCmd{},
 	"pause": &actionCmd{

From 252b94732da87e7da6224897b2b6e6a90400a042 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 30 Aug 2016 17:59:28 -0400
Subject: [PATCH 3/3] lxc: Tweak to --man
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

 - Update help string
 - Add headers for each command
 - Sort the command alphabetically
 - Update translation template

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxc/manpage.go | 20 +++++++++++++++++++-
 po/lxd.pot     | 26 +++++++++++++++-----------
 2 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/lxc/manpage.go b/lxc/manpage.go
index 8bc9b61..db74cbe 100644
--- a/lxc/manpage.go
+++ b/lxc/manpage.go
@@ -1,6 +1,9 @@
 package main
 
 import (
+	"fmt"
+	"sort"
+
 	"github.com/lxc/lxd"
 	"github.com/lxc/lxd/shared/i18n"
 )
@@ -13,7 +16,7 @@ func (c *manpageCmd) showByDefault() bool {
 
 func (c *manpageCmd) usage() string {
 	return i18n.G(
-		`Prints all subcommands help to create a lxd manpage`)
+		`Prints all the subcommands help.`)
 }
 
 func (c *manpageCmd) flags() {
@@ -23,8 +26,23 @@ func (c *manpageCmd) run(_ *lxd.Config, args []string) error {
 	if len(args) > 0 {
 		return errArgs
 	}
+
+	keys := []string{}
 	for k, _ := range commands {
+		keys = append(keys, k)
+	}
+	sort.Strings(keys)
+
+	header := false
+	for _, k := range keys {
+		if header {
+			fmt.Printf("\n\n")
+		}
+
+		fmt.Printf("### lxc %s\n", k)
 		commands["help"].run(nil, []string{k})
+		header = true
 	}
+
 	return nil
 }
diff --git a/po/lxd.pot b/po/lxd.pot
index cbe03b3..ca143a2 100644
--- a/po/lxd.pot
+++ b/po/lxd.pot
@@ -7,7 +7,7 @@
 msgid   ""
 msgstr  "Project-Id-Version: lxd\n"
         "Report-Msgid-Bugs-To: lxc-devel at lists.linuxcontainers.org\n"
-        "POT-Creation-Date: 2016-08-19 09:51-0600\n"
+        "POT-Creation-Date: 2016-08-30 17:59-0400\n"
         "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
         "Last-Translator: FULL NAME <EMAIL at ADDRESS>\n"
         "Language-Team: LANGUAGE <LL at li.org>\n"
@@ -377,7 +377,7 @@ msgstr  ""
 msgid   "ISSUE DATE"
 msgstr  ""
 
-#: lxc/main.go:132
+#: lxc/main.go:136
 msgid   "If this is your first time using LXD, you should also run: sudo lxd init"
 msgstr  ""
 
@@ -790,7 +790,7 @@ msgstr  ""
 msgid   "Only https:// is supported for remote image import."
 msgstr  ""
 
-#: lxc/help.go:63 lxc/main.go:108
+#: lxc/help.go:63 lxc/main.go:112
 msgid   "Options:"
 msgstr  ""
 
@@ -874,6 +874,10 @@ msgstr  ""
 msgid   "Print verbose information."
 msgstr  ""
 
+#: lxc/manpage.go:18
+msgid   "Prints all the subcommands help."
+msgstr  ""
+
 #: lxc/version.go:18
 msgid   "Prints the version number of this client tool.\n"
         "\n"
@@ -1089,7 +1093,7 @@ msgstr  ""
 msgid   "The local image '%s' couldn't be found, trying '%s:' instead."
 msgstr  ""
 
-#: lxc/main.go:175
+#: lxc/main.go:180
 msgid   "The opposite of `lxc pause` is `lxc start`."
 msgstr  ""
 
@@ -1105,7 +1109,7 @@ msgstr  ""
 msgid   "Timestamps:"
 msgstr  ""
 
-#: lxc/main.go:133
+#: lxc/main.go:137
 msgid   "To start your first container, try: lxc launch ubuntu:16.04"
 msgstr  ""
 
@@ -1144,7 +1148,7 @@ msgstr  ""
 msgid   "Uploaded: %s"
 msgstr  ""
 
-#: lxc/main.go:108
+#: lxc/main.go:112
 #, c-format
 msgid   "Usage: %s"
 msgstr  ""
@@ -1209,12 +1213,12 @@ msgstr  ""
 msgid   "enabled"
 msgstr  ""
 
-#: lxc/main.go:22 lxc/main.go:144
+#: lxc/main.go:22 lxc/main.go:148
 #, c-format
 msgid   "error: %v"
 msgstr  ""
 
-#: lxc/help.go:40 lxc/main.go:103
+#: lxc/help.go:40 lxc/main.go:107
 #, c-format
 msgid   "error: unknown command: %s"
 msgstr  ""
@@ -1235,7 +1239,7 @@ msgstr  ""
 msgid   "ok (y/n)?"
 msgstr  ""
 
-#: lxc/main.go:297 lxc/main.go:301
+#: lxc/main.go:302 lxc/main.go:306
 #, c-format
 msgid   "processing aliases failed %s\n"
 msgstr  ""
@@ -1273,11 +1277,11 @@ msgstr  ""
 msgid   "taken at %s"
 msgstr  ""
 
-#: lxc/exec.go:166
+#: lxc/exec.go:163
 msgid   "unreachable return reached"
 msgstr  ""
 
-#: lxc/main.go:229
+#: lxc/main.go:234
 msgid   "wrong number of subcommand arguments"
 msgstr  ""
 


More information about the lxc-devel mailing list