aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 10619d332aca92f672c109e51c1860780a5621b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
How to make CLI tools composing different output formats using [clap](https://crates.io/crates/clap).

Demo:

        $ ./target/debug/rust-clap-output-formats --help
        Usage: rust-clap-output-formats <COMMAND>

        Commands:
          debug  Debug output by default
          text   Text output by default
          api    Unformatted JSON output by default
          json   Pretty formatted JSON output by default
          yaml   YAML output by default
          table  Table output by default
          help   Print this message or the help of the given subcommand(s)

        Options:
          -h, --help  Print help

        $ ./target/debug/rust-clap-output-formats debug --help
        Debug output by default

        Usage: rust-clap-output-formats debug [OPTIONS]

        Options:
              --debug  Display as internal debug representation
              --text   Display as text
              --api    Display as unformatted JSON
          -h, --help   Print help

        $ ./target/debug/rust-clap-output-formats table --help
        Table output by default

        Usage: rust-clap-output-formats table [OPTIONS]

        Options:
              --table  Display as table
              --yaml   Display as YAML
              --json   Display as pretty formatted JSON
              --api    Display as unformatted JSON
              --text   Display as text
              --debug  Display as internal debug representation
          -h, --help   Print help

        $ ./target/debug/rust-clap-output-formats json
        {
          "name": "Hello",
          "value": "world"
        }

        $ ./target/debug/rust-clap-output-formats table
        +-------+-------+
        | Name  | Value |
        +===============+
        | Hello | world |
        +-------+-------+

        $ ./target/debug/rust-clap-output-formats table --json
        {
          "name": "Hello",
          "value": "world"
        }

        $ ./target/debug/rust-clap-output-formats table --yaml
        name: Hello
        value: world