usage/docs/markdown/
spec.rs

1use crate::docs::markdown::renderer::MarkdownRenderer;
2use crate::error::UsageErr;
3
4impl MarkdownRenderer {
5    pub fn render_spec(&self) -> Result<String, UsageErr> {
6        let mut ctx = self.clone();
7        ctx.insert("all_commands", &self.spec.cmd.all_subcommands());
8        ctx.render("spec_template.md.tera")
9    }
10
11    pub fn render_index(&self) -> Result<String, UsageErr> {
12        let mut ctx = self.clone();
13        ctx.multi = false;
14        ctx.insert("all_commands", &self.spec.cmd.all_subcommands());
15        ctx.render("index_template.md.tera")
16    }
17}
18
19#[cfg(test)]
20mod tests {
21    use crate::docs::markdown::renderer::MarkdownRenderer;
22    use crate::test::SPEC_KITCHEN_SINK;
23    use insta::assert_snapshot;
24
25    #[test]
26    fn test_render_markdown_spec() {
27        let ctx = MarkdownRenderer::new(SPEC_KITCHEN_SINK.clone());
28        assert_snapshot!(ctx.render_spec().unwrap(), @r"
29        # `mycli`
30
31        - **Usage**: `mycli [FLAGS] <ARGS>… <SUBCOMMAND>`
32
33        ## Arguments
34
35        ### `<arg1>`
36
37        arg1 description
38
39        ### `[arg2]`
40
41        arg2 description
42
43        **Choices:**
44
45        - `choice1`
46        - `choice2`
47        - `choice3`
48
49        **Default:** `default value`
50
51        ### `<arg3>`
52
53        arg3 long description
54
55        ### `<argrest>...`
56
57        ### `[with-default]`
58
59        **Default:** `default value`
60
61        ## Flags
62
63        ### `--flag1`
64
65        flag1 description
66
67        ### `--flag2`
68
69        flag2 long description
70
71        includes a code block:
72
73            $ echo hello world
74            hello world
75
76            more code
77
78        Examples:
79
80            # run with no arguments to use the interactive selector
81            $ mise use
82
83            # set the current version of node to 20.x in mise.toml of current directory
84            # will write the fuzzy version (e.g.: 20)
85
86        some docs
87
88            $ echo hello world
89            hello world
90
91        ### `--flag3`
92
93        flag3 description
94
95        ### `--with-default`
96
97        **Default:** `default value`
98
99        ### `--shell <shell>`
100
101        **Choices:**
102
103        - `bash`
104        - `zsh`
105        - `fish`
106
107        ## `mycli plugin`
108
109        - **Usage**: `mycli plugin <SUBCOMMAND>`
110        - **Source code**: [`src/cli/plugin.rs`](https://github.com/jdx/mise/blob/main/src/cli/plugin.rs)
111
112        ## `mycli plugin install`
113
114        - **Usage**: `mycli plugin install [FLAGS] <plugin> <version>`
115        - **Source code**: [`src/cli/plugin/install.rs`](https://github.com/jdx/mise/blob/main/src/cli/plugin/install.rs)
116
117        install a plugin
118
119        ### Arguments
120
121        #### `<plugin>`
122
123        #### `<version>`
124
125        ### Flags
126
127        #### `-g --global`
128
129        #### `-d --dir <dir>`
130
131        #### `-f --force`
132        ");
133    }
134}