Skip to content

Commit 9d44a58

Browse files
authored
Merge pull request #76 from warptools/cli-redecorating
cli redecorating
2 parents b365118 + baf87d5 commit 9d44a58

16 files changed

Lines changed: 1249 additions & 27 deletions

File tree

app/_docs/warpforge-catalog.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
title: "wf CLI ref: warpforge catalog"
3+
layout: base.njk
4+
eleventyNavigation:
5+
parent: Warpforge CLI
6+
order: 40
7+
---
8+
9+
10+
`warpforge catalog` command reference
11+
=====================================
12+
13+
[testmark]:# (docs)
14+
```clidoc
15+
## NAME
16+
warpforge catalog - Subcommands that operate on catalogs
17+
18+
## USAGE
19+
warpforge catalog command [command options] [arguments...]
20+
21+
## COMMANDS
22+
### init
23+
Creates a named catalog in the root workspace
24+
25+
### add
26+
Add an item to the given catalog in the root workspace. Will create a catalog if required.
27+
28+
### release
29+
Add a module to the root workspace catalog as a new release
30+
31+
### ls
32+
List available catalogs in the root workspace
33+
34+
### show
35+
Show the contents of a module in the root workspace catalog
36+
37+
### bundle
38+
Bundle required catalog items into the local workspace.
39+
40+
### update
41+
Update remote catalogs in the root workspace. Will install the default warpsys catalog.
42+
43+
### ingest-git-tags
44+
Ingest all tags from a git repository into a root workspace catalog entry
45+
46+
### generate-html
47+
Generates HTML output for the root workspace catalog containing information on modules
48+
49+
### mirror
50+
Mirror the contents of a catalog to remote warehouses
51+
52+
### help, h
53+
Shows a list of commands or help for one command
54+
55+
## OPTIONS
56+
#### --name=<VALUE>, -n=<VALUE>
57+
Name of the catalog to operate on
58+
59+
(default: **"default"**)
60+
61+
#### --force, -f
62+
Force operation, even if it causes data to be overwritten.
63+
64+
(default: **false**)
65+
66+
#### --help, -h
67+
show help
68+
69+
```

app/_docs/warpforge.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
title: "wf CLI ref: warpforge"
3+
layout: base.njk
4+
eleventyNavigation:
5+
parent: Warpforge CLI
6+
order: 40
7+
---
8+
9+
10+
`warpforge` command reference
11+
=============================
12+
13+
[testmark]:# (docs)
14+
```clidoc
15+
## NAME
16+
warpforge - the everything-builder and any-environment manager
17+
18+
## USAGE
19+
See subcommands for details.
20+
21+
## VERSION
22+
v0.4.0
23+
24+
## COMMANDS
25+
### catalog
26+
Subcommands that operate on catalogs
27+
28+
### check
29+
Check file(s) for syntax and sanity
30+
31+
### ferk
32+
Starts a containerized environment for interactive use
33+
34+
### healthcheck
35+
Check for potential errors in system configuration
36+
37+
### plan
38+
Runs planning commands to generate inputs
39+
40+
### quickstart
41+
Generate a basic module and plot
42+
43+
### run
44+
Run a module or formula
45+
46+
### spark
47+
Experimental RPC for getting module build status from the watch server
48+
49+
### status, info
50+
Get status of workspaces and installation
51+
52+
### ware
53+
Subcommands that operate on wares
54+
55+
### watch
56+
Watch a module for changes to plot ingest inputs. Currently only git ingests are supported.
57+
58+
### help, h
59+
Shows a list of commands or help for one command
60+
61+
## GLOBAL OPTIONS
62+
#### --verbose, -v
63+
(default: **false**)
64+
65+
(env var: $**WARPFORGE_DEBUG**)
66+
67+
#### --quiet
68+
(default: **false**)
69+
70+
#### --json
71+
Enable JSON API output
72+
73+
(default: **false**)
74+
75+
#### --trace.file=<VALUE>
76+
Enable tracing and emit output to file
77+
78+
#### --trace.http.enable
79+
Enable remote tracing over http
80+
81+
(default: **false**)
82+
83+
#### --trace.http.insecure
84+
Allows insecure http
85+
86+
(default: **false**)
87+
88+
#### --trace.http.endpoint=<VALUE>
89+
Sets an endpoint for remote open-telemetry tracing collection
90+
91+
#### --help, -h
92+
show help
93+
94+
#### --version
95+
print the version
96+
97+
```

app/app.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ import (
1616
)
1717

1818
var App = appbase.App
19+
20+
func init() {
21+
App.Setup()
22+
}

app/base/appbase.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ import (
66
"io"
77

88
"github.com/urfave/cli/v2"
9+
10+
_ "github.com/warptools/warpforge/app/base/helpgen"
911
)
1012

1113
const VERSION = "v0.4.0"
1214

1315
var App = &cli.App{
14-
Name: "warpforge",
15-
Version: VERSION,
16-
Usage: "the everything-builder and any-environment manager",
16+
Name: "warpforge",
17+
Version: VERSION,
18+
Usage: "the everything-builder and any-environment manager",
19+
UsageText: "See subcommands for details.",
1720

1821
Reader: closedReader{}, // Replace with os.Stdin in real application; or other wiring, in tests.
1922
Writer: panicWriter{}, // Replace with os.Stdout in real application; or other wiring, in tests.
@@ -84,7 +87,9 @@ var App = &cli.App{
8487
// Aaaand the other modifications to `urfave/cli` that are unfortunately only possible by manipulating globals:
8588
func init() {
8689
cli.VersionFlag = &cli.BoolFlag{
87-
Name: "version", // And no short aliases. "-v" is for "verbose"!
90+
Name: "version", // And no short aliases. "-v" is for "verbose"!
91+
Usage: "print the version",
92+
DisableDefaultText: true,
8893
}
8994
}
9095

app/base/helpgen/helpgen.go

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
This package contains our custom help text generators,
3+
and wires them into `urfave/cli` at package init time.
4+
5+
We use templates which emit markdown.
6+
Optionally, this can be subsequently post-processed to be
7+
converted to nicer terminal rendering using ANSI codes --
8+
this feature is in another package, so you can disable it.
9+
10+
(The use of package init time is unfortunate,
11+
but package sideeffects cannot be avoided:
12+
package-scope vars are the only option for customizing help processing
13+
that the `urfave/cli` package currently makes available.)
14+
*/
15+
package helpgen
16+
17+
import (
18+
"bytes"
19+
"io"
20+
"strings"
21+
"text/tabwriter"
22+
"text/template"
23+
24+
"github.com/urfave/cli/v2"
25+
"github.com/warptools/warpforge/app/base/render"
26+
)
27+
28+
/*
29+
A guide to how to use the various docs strings in a cli.Command in our system:
30+
31+
- Usage -- this should be a one-liner, used to describe this command in the parent command's overview of its children.
32+
- UsageText -- this should contain a synopsys, with examples of how to use the command and its flags. May be multi-line.
33+
- Description -- freetext prose; may be multi-line. Shows up in the `-h` for that command.
34+
- ArgsUsage -- UNUSED. (TODO:CONSIDER: maybe use this for synopsys, and repurpose UsageText for bighelp? Or otherwise shuffle the deck chairs.)
35+
36+
And outside of this:
37+
38+
- longer helptext for the `{appname} help {subcommandname}` feature -- that isn't actually a feature we've implemented yet.
39+
If it comes, it might be based on munging the Description field. (e.g., peeking for "---" or similar, on the assumption that isn't actually needed in real content.)
40+
41+
For documenting cli.Flag:
42+
43+
- there's really only the Usage fields, per type.
44+
- Short and long isn't disambiguated here either.
45+
(As with commands, if we introduce this, it might be possibly to do it by munging format cues in-band.)
46+
*/
47+
48+
// printHelpCustom is the entrypoint for `urfave/cli`'s customization.
49+
//
50+
// See the function of the same name upstream for reference.
51+
// This function is considerably derived from it.
52+
func printHelpCustom(out io.Writer, tmpl string, data interface{}, customFuncs map[string]interface{}) {
53+
54+
const hardwrap = 10000
55+
56+
funcMap := template.FuncMap{
57+
"join": strings.Join,
58+
"subtract": subtract,
59+
"indent": indent,
60+
"nindent": nindent,
61+
"trim": strings.TrimSpace,
62+
"wrap": func(input string, offset int) string { return wrap(input, offset, hardwrap) },
63+
"offset": offset,
64+
"offsetCommands": offsetCommands,
65+
}
66+
for key, value := range customFuncs {
67+
funcMap[key] = value
68+
}
69+
70+
var buf bytes.Buffer
71+
w := tabwriter.NewWriter(&buf, 1, 8, 4, ' ', 0)
72+
t := template.Must(template.New("help").Funcs(funcMap).Parse(tmpl))
73+
template.Must(t.New("helpNameTemplate").Parse(helpNameTemplate))
74+
template.Must(t.New("usageTemplate").Parse(usageTemplate))
75+
template.Must(t.New("visibleCommandTemplate").Parse(visibleCommandTemplate))
76+
template.Must(t.New("visibleFlagCategoryTemplate").Parse(visibleFlagCategoryTemplate))
77+
template.Must(t.New("visibleFlagTemplate").Parse(visibleFlagTemplate))
78+
template.Must(t.New("visibleGlobalFlagCategoryTemplate").Parse(strings.Replace(visibleFlagCategoryTemplate, "OPTIONS", "GLOBAL OPTIONS", -1)))
79+
template.Must(t.New("authorsTemplate").Parse(authorsTemplate))
80+
template.Must(t.New("visibleCommandCategoryTemplate").Parse(visibleCommandCategoryTemplate))
81+
82+
err := t.Execute(w, data)
83+
if err != nil {
84+
panic(err)
85+
}
86+
_ = w.Flush()
87+
88+
if err := render.Render(buf.Bytes(), out, Mode); err != nil {
89+
panic(err)
90+
}
91+
}
92+
93+
var Mode = render.Mode_ANSIdown
94+
95+
func init() {
96+
cli.HelpPrinterCustom = printHelpCustom
97+
}

0 commit comments

Comments
 (0)