Skip to content

Commit

Permalink
Merge pull request juju#8003 from anastasiamac/help-tool-help
Browse files Browse the repository at this point in the history
Fixes lp#1628148: help help-tool.

## Description of change

Adding more context to help for help-tool.

## Bug reference

https://bugs.launchpad.net/juju/+bug/1628148
  • Loading branch information
jujubot authored Nov 2, 2017
2 parents 7542d6c + 94f51b8 commit 7d6f9b4
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 24 deletions.
67 changes: 45 additions & 22 deletions cmd/juju/commands/helptool.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,13 @@ type helpToolCommand struct {

func (t *helpToolCommand) Info() *cmd.Info {
return &cmd.Info{
Name: "help-tool",
Name: "hook-tool",
Args: "[tool]",
Purpose: "Show help on a Juju charm tool.",
Purpose: "Show help on a Juju charm hook tool.",
Doc: helpToolDoc,
Aliases: []string{
"help-tool", // TODO (anastasimac 2017-11-1) This should be removed in Juju 3.
"hook-tools"},
}
}

Expand All @@ -115,28 +119,10 @@ func (t *helpToolCommand) Init(args []string) error {
}

func (c *helpToolCommand) Run(ctx *cmd.Context) error {
var hookctx dummyHookContext
if c.tool == "" {
// Ripped from SuperCommand. We could Run() a SuperCommand
// with "help commands", but then the implicit "help" command
// shows up.
names := jujuc.CommandNames()
cmds := make([]cmd.Command, 0, len(names))
longest := 0
for _, name := range names {
if c, err := jujuc.NewCommand(hookctx, name); err == nil {
if len(name) > longest {
longest = len(name)
}
cmds = append(cmds, c)
}
}
for _, c := range cmds {
info := c.Info()
fmt.Fprintf(ctx.Stdout, "%-*s %s\n", longest, info.Name, info.Purpose)
}
fmt.Fprintf(ctx.Stdout, listHookTools())
} else {
c, err := jujuc.NewCommand(hookctx, c.tool)
c, err := jujuc.NewCommand(dummyHookContext{}, c.tool)
if err != nil {
return err
}
Expand All @@ -147,3 +133,40 @@ func (c *helpToolCommand) Run(ctx *cmd.Context) error {
}
return nil
}

var helpToolDoc = fmt.Sprintf(`
Juju charms can access a series of built-in helpers called 'hook-tools'.
These are useful for the charm to be able to inspect its running environment.
Currently available charm hook tools are:
%v
Examples:
For help on a specific tool, supply the name of that tool, for example:
juju hook-tool unit-get
`, listHookTools())

func listHookTools() string {
all := ""
// Ripped from SuperCommand. We could Run() a SuperCommand
// with "help commands", but then the implicit "help" command
// shows up.
names := jujuc.CommandNames()
cmds := []cmd.Command{}
longest := 0
for _, name := range names {
if c, err := jujuc.NewCommand(dummyHookContext{}, name); err == nil {
if len(name) > longest {
longest = len(name)
}
cmds = append(cmds, c)
}
}
for _, c := range cmds {
info := c.Info()
all += fmt.Sprintf(" %-*s %s\n", longest, info.Name, info.Purpose)
}
return all
}
43 changes: 41 additions & 2 deletions cmd/juju/commands/helptool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,49 @@ var _ = gc.Suite(&HelpToolSuite{})

func (suite *HelpToolSuite) TestHelpToolHelp(c *gc.C) {
output := badrun(c, 0, "help", "help-tool")
c.Assert(output, gc.Equals, `Usage: juju help-tool [tool]
c.Assert(output, gc.Equals, `Usage: juju hook-tool [tool]
Summary:
Show help on a Juju charm tool.
Show help on a Juju charm hook tool.
Details:
Juju charms can access a series of built-in helpers called 'hook-tools'.
These are useful for the charm to be able to inspect its running environment.
Currently available charm hook tools are:
action-fail set action fail status with message
action-get get action parameters
action-set set action results
add-metric add metrics
application-version-set specify which version of the application is deployed
close-port ensure a port or range is always closed
config-get print application configuration
is-leader print application leadership status
juju-log write a message to the juju log
juju-reboot Reboot the host machine
leader-get print application leadership settings
leader-set write application leadership settings
network-get get network config
open-port register a port or range to open
opened-ports lists all ports or ranges opened by the unit
relation-get get relation settings
relation-ids list all relation ids with the given relation name
relation-list list relation units
relation-set set relation settings
status-get print status information
status-set set status information
storage-add add storage instances
storage-get print information for storage instance with specified id
storage-list list storage attached to the unit
unit-get print public-address or private-address
Examples:
For help on a specific tool, supply the name of that tool, for example:
juju hook-tool unit-get
Aliases: help-tool, hook-tools
`)
}

Expand Down
2 changes: 2 additions & 0 deletions cmd/juju/commands/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,8 @@ var commandNames = []string{
"gui",
"help",
"help-tool",
"hook-tool",
"hook-tools",
"import-filesystem",
"import-ssh-key",
"kill-controller",
Expand Down

0 comments on commit 7d6f9b4

Please sign in to comment.