Skip to content

Commit 5ad2547

Browse files
authored
Docs improvements (#29)
1 parent fd76778 commit 5ad2547

File tree

4 files changed

+163
-57
lines changed

4 files changed

+163
-57
lines changed

README.md

Lines changed: 36 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,61 +3,13 @@
33
`zxc` is a directory-oriented command runner.
44
This means it is able to run commands defined by YAML files.
55

6-
## Basics of operation
6+
## Features
77

8-
### Definition files location
8+
- YAML-based definition - human-readable and easy to write
9+
- Jinja-based template substitution - flexible
10+
- native look and feel
911

10-
Definition files are searched for in two places:
11-
12-
- local - from CWD.
13-
- external - from `$HOME/.zxc/<mirrored CWD path>`.
14-
E.g., if CWD is `/opt/app/` then `$HOME/.zxc/opt/app/` should be used.
15-
16-
Following file names are allowed:
17-
18-
- `.zxc.yml`
19-
- `.zxc.yaml`
20-
- `zxc.yml`
21-
- `zxc.yaml`
22-
23-
It's expected that at least one definition file is found.
24-
It's not allowed to have multiple definition files in one directory.
25-
26-
External definition file takes precedence.
27-
This might cause command to be overwritten if defined in both files.
28-
29-
### Definition file
30-
31-
#### Defining a command
32-
33-
Following fields are used to define a command:
34-
35-
- command name is used as a key
36-
- `command` - shell command to run - mandatory
37-
- `description` - description - optional
38-
- `arguments` - arguments - optional
39-
40-
#### Defining an argument
41-
42-
Following fields are used to define an argument:
43-
44-
- argument name is used as a key
45-
- `flags` - list of flags - mandatory
46-
- named arguments contain flags starting with `-` and/or `--`:
47-
- multiple short/long flags cannot be defined for the same argument
48-
- 1 or 2 flags are expected
49-
- positional arguments contain flag not starting with `-` or `--`.
50-
- argument cannot be simultanously named and positional
51-
- `default` - default value - optional
52-
- argument is considered required if default value is not specified
53-
- `description` - description - optional
54-
55-
### Argument substitution
56-
57-
Jinja is used as a template engine.
58-
`command` field can contain double curly braces to provide arguments to the command.
59-
60-
### Example
12+
## Example
6113

6214
Simple definition file:
6315

@@ -73,10 +25,37 @@ greet:
7325
Name to greet.
7426
```
7527
76-
Use following command to print `Hello John!`:
28+
Refer to [definition file documentation](./docs/definition_file.md) for more information.
29+
30+
Use following command to print `Hello world!`:
7731

7832
```bash
79-
zxc greet --name John
33+
zxc greet --name world
34+
```
35+
36+
![demo](./docs/demo.svg)
37+
38+
## Installation
39+
40+
### From source
41+
42+
```bash
43+
cargo build --release
44+
cargo install --path .
45+
```
46+
47+
### From packages
48+
49+
`deb`-based systems:
50+
51+
```bash
52+
sudo dpkg -i zxc_<version>-1_amd64.deb
53+
```
54+
55+
`rpm`-based systems:
56+
57+
```bash
58+
sudo rpm -i zxc-<version>-1.x86_64.rpm
8059
```
8160

8261
## Development
@@ -95,12 +74,12 @@ pre-commit install
9574
pre-commit run -a
9675
```
9776

98-
## Build and install
77+
### Build, test and install
9978

10079
```bash
10180
cargo build --release
102-
cargo install --path .
10381
cargo test
82+
cargo install --path .
10483
```
10584

10685
### Create packages

docs/definition_file.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Definition file
2+
3+
This file contains description of definition file.
4+
5+
## Location
6+
7+
Definition files are searched for in two places:
8+
9+
- local - from CWD.
10+
- external - from `$HOME/.zxc/<mirrored CWD path>`.
11+
E.g., if CWD is `/opt/app/` then `$HOME/.zxc/opt/app/` should be used.
12+
13+
Following file names are allowed:
14+
15+
- `.zxc.yml`
16+
- `.zxc.yaml`
17+
- `zxc.yml`
18+
- `zxc.yaml`
19+
20+
It's expected that at least one definition file is found.
21+
It's not allowed to have multiple definition files in one directory.
22+
23+
External definition file takes precedence.
24+
This might cause command to be overwritten if defined in both files.
25+
26+
## Structure
27+
28+
### Defining a command
29+
30+
Following fields are used to define a command:
31+
32+
- command name is used as a key
33+
- `command` - shell command to run - mandatory
34+
- `description` - description - optional
35+
- `arguments` - arguments - optional
36+
37+
### Defining an argument
38+
39+
Following fields are used to define an argument:
40+
41+
- argument name is used as a key
42+
- `flags` - list of flags - mandatory
43+
- named arguments contain flags starting with `-` and/or `--`:
44+
- multiple short/long flags cannot be defined for the same argument
45+
- 1 or 2 flags are expected
46+
- positional arguments contain flag not starting with `-` or `--`.
47+
- argument cannot be simultanously named and positional
48+
- `default` - default value - optional
49+
- argument is considered required if default value is not specified
50+
- `description` - description - optional
51+
52+
### Argument substitution
53+
54+
Jinja is used as a template engine.
55+
`command` field can contain double curly braces to provide arguments to the command.

docs/demo.cast

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{"version": 2, "width": 120, "height": 39, "timestamp": 1751715824, "idle_time_limit": 1.0, "env": {"SHELL": "/bin/bash", "TERM": "tmux-256color"}}
2+
[0.044619, "o", "\u001b[?2004h$ "]
3+
[4.027023, "o", "c"]
4+
[4.093216, "o", "a"]
5+
[4.296752, "o", "t"]
6+
[4.408683, "o", " "]
7+
[4.657105, "o", "."]
8+
[4.859715, "o", "z"]
9+
[4.926795, "o", "x"]
10+
[5.336817, "o", "c.yml "]
11+
[6.186706, "o", "\r\n\u001b[?2004l\r"]
12+
[6.188329, "o", "greet:\r\n command: echo \"Hello {{ name }}!\"\r\n description: Greets specified person.\r\n arguments:\r\n name:\r\n flags: [\"-n\", \"--name\"]\r\n default: User\r\n description: |-\r\n Name to greet.\r\n"]
13+
[6.188573, "o", "\u001b[?2004h$ "]
14+
[8.166947, "o", "z"]
15+
[8.278424, "o", "x"]
16+
[8.346726, "o", "c"]
17+
[8.481338, "o", " "]
18+
[8.638277, "o", "-"]
19+
[8.818965, "o", "-"]
20+
[9.021692, "o", "h"]
21+
[9.111704, "o", "e"]
22+
[9.381747, "o", "l"]
23+
[9.425991, "o", "p"]
24+
[9.921486, "o", "\r\n\u001b[?2004l\r"]
25+
[9.923387, "o", "`zxc` is a directory-oriented command runner.\r\nThis means it is able to run commands defined by YAML files.\r\n\r\n\u001b[1m\u001b[4mUsage:\u001b[0m \u001b[1mzxc\u001b[0m <COMMAND>\r\n\r\n\u001b[1m\u001b[4mCommands:\u001b[0m\r\n \u001b[1mgreet\u001b[0m Greets specified person.\r\n \r\n Command: echo \"Hello {{ name }}!\"\r\n \u001b[1mhelp\u001b[0m Print this message or the help of the given subcommand(s)\r\n\r\n\u001b[1m\u001b[4mOptions:\u001b[0m\r\n \u001b[1m-h\u001b[0m, \u001b[1m--help\u001b[0m Print help\r\n \u001b[1m-V\u001b[0m, \u001b[1m--version\u001b[0m Print version\r\n"]
26+
[9.92379, "o", "\u001b[?2004h$ "]
27+
[11.42907, "o", "z"]
28+
[11.518818, "o", "x"]
29+
[11.586331, "o", "c"]
30+
[11.946921, "o", " "]
31+
[12.711525, "o", "g"]
32+
[12.913782, "o", "r"]
33+
[12.958654, "o", "e"]
34+
[13.16194, "o", "e"]
35+
[13.230291, "o", "t"]
36+
[13.386404, "o", " "]
37+
[13.566821, "o", "-"]
38+
[13.746714, "o", "-"]
39+
[13.926738, "o", "h"]
40+
[14.017638, "o", "e"]
41+
[14.242104, "o", "l"]
42+
[14.286895, "o", "p"]
43+
[15.096697, "o", "\r\n\u001b[?2004l\r"]
44+
[15.098556, "o", "Greets specified person.\r\n\r\nCommand: echo \"Hello {{ name }}!\"\r\n\r\n\u001b[1m\u001b[4mUsage:\u001b[0m \u001b[1mzxc greet\u001b[0m [OPTIONS]\r\n\r\n\u001b[1m\u001b[4mOptions:\u001b[0m\r\n \u001b[1m-n\u001b[0m, \u001b[1m--name\u001b[0m <name> Name to greet. [default: User]\r\n \u001b[1m-h\u001b[0m, \u001b[1m--help\u001b[0m Print help\r\n"]
45+
[15.098963, "o", "\u001b[?2004h$ "]
46+
[17.616816, "o", "z"]
47+
[17.706205, "o", "x"]
48+
[17.774051, "o", "c"]
49+
[17.886288, "o", " "]
50+
[18.066419, "o", "g"]
51+
[18.493719, "o", "r"]
52+
[18.606244, "o", "e"]
53+
[18.789977, "o", "e"]
54+
[18.898924, "o", "t"]
55+
[19.011787, "o", " "]
56+
[19.326664, "o", "-"]
57+
[19.461633, "o", "-"]
58+
[19.641949, "o", "n"]
59+
[19.687082, "o", "a"]
60+
[19.821206, "o", "m"]
61+
[19.888955, "o", "e"]
62+
[20.002023, "o", " "]
63+
[20.969084, "o", "w"]
64+
[21.058765, "o", "o"]
65+
[21.486245, "o", "r"]
66+
[21.598832, "o", "l"]
67+
[21.711747, "o", "d"]
68+
[22.206956, "o", "\r\n\u001b[?2004l\r"]
69+
[22.210662, "o", "Hello world!\r\n"]
70+
[22.21135, "o", "\u001b[?2004h$ "]
71+
[23.826833, "o", "\u001b[?2004l\r\r\nexit\r\n"]

docs/demo.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)