Skip to content

Commit c0b23a0

Browse files
committed
Update documentation
1 parent e8178e8 commit c0b23a0

File tree

10 files changed

+130
-38
lines changed

10 files changed

+130
-38
lines changed

README.md

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
# tome-cli
22

3-
43
A rewrite of [`sub`](https://github.com/qrush/sub) and [`tome`](https://github.com/toumorokoshi/tome) and my fork of [tome](https://github.com/zph/tome) but with a different internal implementation in order to support:
54
1. Improved auto-completion
65
2. Improved usage/help outputs
76
3. Faster development
87
4. Testable interfaces
98

10-
# Interface
9+
# Usage
1110

1211
```
13-
export TOME_ROOT=examples
14-
tome-cli exec path to file
15-
tome-cli help path to <TAB>
16-
tome-cli completion fish | source
17-
tome-cli alias --write kit
18-
1912
# shorthand syntax via bash wrapper script
2013
tome-cli --executable kit alias --output ~/bin/kit
2114
@@ -24,11 +17,37 @@ kit completion fish | source
2417
kit path to file
2518
kit pat<TAB>
2619
20+
# Long form
21+
export TOME_ROOT=examples
22+
tome-cli exec path to file
23+
tome-cli help path to <TAB>
24+
tome-cli completion fish | source
25+
26+
# Setup tab completion
27+
tome-cli completion fish | source
28+
eval "$(tome-cli completion zsh)"
2729
28-
# Print out completions for zsh | fish | bash
29-
tome completion zsh
30+
# See instructions for a command
31+
tome-cli completion --help
3032
```
3133

34+
See [docs](./docs/tome-cli.md) for expanded instructions
35+
36+
# Features
37+
38+
- Organize a folder of scripts into a CLI sdk
39+
- Any language is supported via normal script `#!`
40+
- Usage text extracted from script header if `USAGE: ` is included in leading comments
41+
- Full help text extracted as lines from `USAGE: ` to first empty line
42+
- Builtin alias generator allows for embedding configuration flags via tome-cli [alias](./docs/tome-cli_alias.md)
43+
- Auto completion of:
44+
- subcommands (exec, help, etc)
45+
- root folder's folder names
46+
- root folder's scripts
47+
- root script's flags and arguments (when they satisfy the --complete and TOME_COMPLETION interface)
48+
- Gitignore like syntax for ignoring scripts by using a `.tome_ignore` file at base of root folder
49+
-
50+
3251
# Capabilities
3352

3453
- [x] exec scripts in a directory
@@ -51,8 +70,8 @@ tome completion zsh
5170
- [x] auto-complete script arguments (scripts that include the text TOME_COMPLETION which are tab completed will try to get autocompletes from the script via executing it with --completion)
5271
- [x] injects TOME_ROOT into tooling as env var and TOME_EXECUTABLE
5372
- [x] Add level and k/v style logging
54-
- [ ] Add instructions to README
55-
- [ ] Generate a docs folder for more full instructions (https://umarcor.github.io/cobra/#generating-markdown-docs-for-your-own-cobracommand)
73+
- [x] Add instructions to README
74+
- [x] Generate a docs folder for more full instructions (https://umarcor.github.io/cobra/#generating-markdown-docs-for-your-own-cobracommand)
5675
- [ ] See if there's utility in ActiveHelp https://umarcor.github.io/cobra/#active-help
5776
- [ ] pre-hooks (hooks.d folder will be sourced in order or executed before the real script)
5877
- [ ] https://umarcor.github.io/cobra/#prerun-and-postrun-hooks
@@ -68,9 +87,3 @@ tome completion zsh
6887
## Non Features
6988

7089
- Does not support sourcing scripts into shell environment because it adds implementation complexity for other core commands
71-
72-
# Alternate names
73-
74-
kit
75-
edc or eds (everyday scripting)
76-
grimoire

cmd/alias.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,24 @@ var aliasCmd = &cobra.Command{
2828
Use: "alias",
2929
Short: "Create an alias wrapper for tome-cli",
3030
Long: `The alias command allows you to create an alias for the tome command.
31-
This can be useful if you wish to embed common flags like root and executable name and alias the command as a different name.
32-
The generated script uses the executable name and root directory specified in the tome configuration file.`,
31+
32+
The alias command allows you to create an alias for the tome command.
33+
34+
An alias is a shell script that embeds common flags like root and executable
35+
name and can be stored as an alternate name.
36+
37+
The generated script uses the executable name and root directory specified in the tome configuration file.
38+
39+
To use it:
40+
41+
The following command will create an alias script in the ~/bin directory named 'kit'
42+
which embeds the root directory and executable name so that 'kit' can be used in normal
43+
circumstances with no flags or environment variables.
44+
45+
$> tome-cli --root $PWD/examples --executable kit alias --output ~/bin/kit
46+
47+
Read the template script 'tome-wrapper.sh.tmpl' for more information on how the alias is created
48+
`,
3349
Run: func(cmd *cobra.Command, args []string) {
3450
config := NewConfig()
3551
s := ScriptTemplate{

cmd/completion.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ PowerShell:
5555
# To load completions for every new session, run:
5656
PS> %[1]s completion powershell > %[1]s.ps1
5757
# and source this file from your PowerShell profile.
58+
59+
Using completions from within child scripts
60+
61+
Once completions discover an executable and non-ignored script,
62+
tome-cli will check if the script has TOME_COMPLETION declared in file.
63+
If so, it will attempt fetch completions from the script itself.
64+
65+
This is accomplished by passing --complete to the script and capturing the output.
66+
67+
The output syntax is newline-separated strings where each line is composed of
68+
a completion (e.g. a flag or argument), a tab character, and a description of the completion.
69+
5870
`, rootCmd.Name()),
5971
DisableFlagsInUseLine: true,
6072
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},

cmd/docs.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ import (
1212

1313
// docsCmd represents the docs command
1414
var docsCmd = &cobra.Command{
15-
Use: "docs",
16-
Short: "Create docs for tome-cli",
15+
Use: "docs",
16+
Short: "Create docs for tome-cli",
17+
Long: `The docs command generates markdown documentation for the tome-cli command.
18+
19+
It's hidden from the help menu because it's not a user-facing command.`,
1720
Hidden: true,
1821
Run: func(cmd *cobra.Command, args []string) {
1922
err := doc.GenMarkdownTree(rootCmd, "docs")

cmd/exec.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,23 @@ var execCmd = &cobra.Command{
105105
Use: "exec",
106106
Short: "executes a script from tome root",
107107
Long: dedent.Dedent(`
108-
The exec command executes a script file with the provided arguments.
108+
Usage: tome-cli exec <path-to> <script> [args...]
109109
110-
The exec command will search for the script file in the root directory
111-
specified in the tome configuration flags or env vars.
110+
The exec command executes a script file with the provided arguments.
112111
113-
Scripts are searched for in the root directory and subdirectories and
114-
then are called with execvp to replace the current process.
112+
The exec command will search for the script file in the root directory
113+
specified in the tome configuration flags or env vars. Paths will be
114+
joined with the root directory, the intervening directories, and
115+
the script file name.
116+
117+
When executed, the script will be become the tome-cli process through
118+
the syscall.Exec function.
119+
120+
TOME_ROOT and TOME_EXECUTABLE are injected into the environment as well
121+
as the executable name as an uppercased snake case string.
122+
123+
If the executable name is 'kit' the additional environment variables would be:
124+
KIT_ROOT, KIT_EXECUTABLE.
115125
`),
116126
RunE: ExecRunE,
117127
ValidArgsFunction: ValidArgsFunctionForScripts,

docs/tome-cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ tome-cli [flags]
3232
* [tome-cli exec](tome-cli_exec.md) - executes a script from tome root
3333
* [tome-cli help](tome-cli_help.md) - help displays the usage and help text for a script
3434

35-
###### Auto generated by spf13/cobra on 3-Aug-2024
35+
###### Auto generated by spf13/cobra on 5-Aug-2024

docs/tome-cli_alias.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,25 @@ Create an alias wrapper for tome-cli
55
### Synopsis
66

77
The alias command allows you to create an alias for the tome command.
8-
This can be useful if you wish to embed common flags like root and executable name and alias the command as a different name.
8+
9+
The alias command allows you to create an alias for the tome command.
10+
11+
An alias is a shell script that embeds common flags like root and executable
12+
name and can be stored as an alternate name.
13+
914
The generated script uses the executable name and root directory specified in the tome configuration file.
1015

16+
To use it:
17+
18+
The following command will create an alias script in the ~/bin directory named 'kit'
19+
which embeds the root directory and executable name so that 'kit' can be used in normal
20+
circumstances with no flags or environment variables.
21+
22+
$> tome-cli --root $PWD/examples --executable kit alias --output ~/bin/kit
23+
24+
Read the template script 'tome-wrapper.sh.tmpl' for more information on how the alias is created
25+
26+
1127
```
1228
tome-cli alias [flags]
1329
```
@@ -31,4 +47,4 @@ tome-cli alias [flags]
3147

3248
* [tome-cli](tome-cli.md) - A cli tool to manage scripts as a set of subcommands
3349

34-
###### Auto generated by spf13/cobra on 3-Aug-2024
50+
###### Auto generated by spf13/cobra on 5-Aug-2024

docs/tome-cli_completion.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ PowerShell:
4343
PS> tome-cli completion powershell > tome-cli.ps1
4444
# and source this file from your PowerShell profile.
4545

46+
Using completions from within child scripts
47+
48+
Once completions discover an executable and non-ignored script,
49+
tome-cli will check if the script has TOME_COMPLETION declared in file.
50+
If so, it will attempt fetch completions from the script itself.
51+
52+
This is accomplished by passing --complete to the script and capturing the output.
53+
54+
The output syntax is newline-separated strings where each line is composed of
55+
a completion (e.g. a flag or argument), a tab character, and a description of the completion.
56+
57+
4658

4759
```
4860
tome-cli completion [bash|zsh|fish|powershell]
@@ -66,4 +78,4 @@ tome-cli completion [bash|zsh|fish|powershell]
6678

6779
* [tome-cli](tome-cli.md) - A cli tool to manage scripts as a set of subcommands
6880

69-
###### Auto generated by spf13/cobra on 3-Aug-2024
81+
###### Auto generated by spf13/cobra on 5-Aug-2024

docs/tome-cli_exec.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,23 @@ executes a script from tome root
55
### Synopsis
66

77

8-
The exec command executes a script file with the provided arguments.
8+
Usage: tome-cli exec <path-to> <script> [args...]
99

10-
The exec command will search for the script file in the root directory
11-
specified in the tome configuration flags or env vars.
10+
The exec command executes a script file with the provided arguments.
1211

13-
Scripts are searched for in the root directory and subdirectories and
14-
then are called with execvp to replace the current process.
12+
The exec command will search for the script file in the root directory
13+
specified in the tome configuration flags or env vars. Paths will be
14+
joined with the root directory, the intervening directories, and
15+
the script file name.
16+
17+
When executed, the script will be become the tome-cli process through
18+
the syscall.Exec function.
19+
20+
TOME_ROOT and TOME_EXECUTABLE are injected into the environment as well
21+
as the executable name as an uppercased snake case string.
22+
23+
If the executable name is 'kit' the additional environment variables would be:
24+
KIT_ROOT, KIT_EXECUTABLE.
1525

1626

1727
```
@@ -37,4 +47,4 @@ tome-cli exec [flags]
3747

3848
* [tome-cli](tome-cli.md) - A cli tool to manage scripts as a set of subcommands
3949

40-
###### Auto generated by spf13/cobra on 3-Aug-2024
50+
###### Auto generated by spf13/cobra on 5-Aug-2024

docs/tome-cli_help.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ tome-cli help [flags]
4848

4949
* [tome-cli](tome-cli.md) - A cli tool to manage scripts as a set of subcommands
5050

51-
###### Auto generated by spf13/cobra on 3-Aug-2024
51+
###### Auto generated by spf13/cobra on 5-Aug-2024

0 commit comments

Comments
 (0)