Skip to main content

DescribableBuilder

Struct DescribableBuilder 

Source
pub struct DescribableBuilder { /* private fields */ }
Expand description

Builder for attaching examples, IO descriptors, and auth config to commands before checking --mtp-describe.

Implementations§

Source§

impl DescribableBuilder

Source

pub fn new() -> Self

Examples found in repository?
examples/filetool.rs (line 50)
49fn main() {
50    let cli: Cli = DescribableBuilder::new()
51        .example(
52            "convert",
53            "Convert a CSV file to JSON",
54            "filetool convert data.csv --format json --pretty",
55            Some("[{\n  \"name\": \"Alice\",\n  \"age\": 30\n}]"),
56        )
57        .example(
58            "convert",
59            "Pipe from stdin",
60            "cat data.csv | filetool convert - --format yaml",
61            None,
62        )
63        .stdin(
64            "convert",
65            "text/plain",
66            "Raw input data (alternative to file path)",
67        )
68        .stdout("convert", "application/json", "Converted output")
69        .example(
70            "validate",
71            "Validate a JSON file",
72            "filetool validate config.json",
73            Some("{\"valid\": true, \"errors\": []}"),
74        )
75        .example(
76            "process",
77            "Process a JSON object from stdin",
78            "echo '{\"name\":\"foo\",\"count\":3}' | filetool process",
79            Some("{\"status\": \"ok\", \"processed\": \"foo\"}"),
80        )
81        .stdin_with_schema(
82            "process",
83            "application/json",
84            "JSON object to process",
85            serde_json::json!({
86                "type": "object",
87                "properties": {
88                    "name": {"type": "string", "description": "Item name"},
89                    "count": {"type": "integer", "description": "Number of items"}
90                },
91                "required": ["name"]
92            }),
93        )
94        .stdout("process", "application/json", "Processing result")
95        .auth(AuthConfig {
96            required: Some(false),
97            env_var: "FILETOOL_TOKEN".to_string(),
98            providers: vec![
99                AuthProvider {
100                    id: "github".to_string(),
101                    provider_type: "oauth2".to_string(),
102                    display_name: Some("GitHub".to_string()),
103                    authorization_url: Some(
104                        "https://github.com/login/oauth/authorize".to_string(),
105                    ),
106                    token_url: Some(
107                        "https://github.com/login/oauth/access_token".to_string(),
108                    ),
109                    scopes: Some(vec!["repo".to_string(), "read:user".to_string()]),
110                    client_id: Some("Ov23lixyz".to_string()),
111                    registration_url: None,
112                    instructions: None,
113                },
114                AuthProvider {
115                    id: "api-key".to_string(),
116                    provider_type: "api-key".to_string(),
117                    display_name: Some("API Key".to_string()),
118                    authorization_url: None,
119                    token_url: None,
120                    scopes: None,
121                    client_id: None,
122                    registration_url: Some("https://example.com/settings/keys".to_string()),
123                    instructions: Some(
124                        "Create a key at https://example.com/settings/keys".to_string(),
125                    ),
126                },
127            ],
128        })
129        .command_auth(
130            "process",
131            CommandAuth {
132                required: Some(true),
133                scopes: Some(vec!["write".to_string()]),
134            },
135        )
136        .parse();
137
138    match cli {
139        Cli::Convert {
140            input_file,
141            format,
142            pretty,
143        } => {
144            println!(
145                "Converting {} to {}{}",
146                input_file,
147                format,
148                if pretty { " (pretty)" } else { "" }
149            );
150        }
151        Cli::Validate {
152            input_file,
153            strict,
154        } => {
155            println!(
156                "Validating {}{}",
157                input_file,
158                if strict { " (strict)" } else { "" }
159            );
160        }
161        Cli::Process { verbose } => {
162            println!("Processing (verbose={})", verbose);
163        }
164    }
165}
Source

pub fn example( self, command_name: &str, description: &str, invocation: &str, output: Option<&str>, ) -> Self

Examples found in repository?
examples/filetool.rs (lines 51-56)
49fn main() {
50    let cli: Cli = DescribableBuilder::new()
51        .example(
52            "convert",
53            "Convert a CSV file to JSON",
54            "filetool convert data.csv --format json --pretty",
55            Some("[{\n  \"name\": \"Alice\",\n  \"age\": 30\n}]"),
56        )
57        .example(
58            "convert",
59            "Pipe from stdin",
60            "cat data.csv | filetool convert - --format yaml",
61            None,
62        )
63        .stdin(
64            "convert",
65            "text/plain",
66            "Raw input data (alternative to file path)",
67        )
68        .stdout("convert", "application/json", "Converted output")
69        .example(
70            "validate",
71            "Validate a JSON file",
72            "filetool validate config.json",
73            Some("{\"valid\": true, \"errors\": []}"),
74        )
75        .example(
76            "process",
77            "Process a JSON object from stdin",
78            "echo '{\"name\":\"foo\",\"count\":3}' | filetool process",
79            Some("{\"status\": \"ok\", \"processed\": \"foo\"}"),
80        )
81        .stdin_with_schema(
82            "process",
83            "application/json",
84            "JSON object to process",
85            serde_json::json!({
86                "type": "object",
87                "properties": {
88                    "name": {"type": "string", "description": "Item name"},
89                    "count": {"type": "integer", "description": "Number of items"}
90                },
91                "required": ["name"]
92            }),
93        )
94        .stdout("process", "application/json", "Processing result")
95        .auth(AuthConfig {
96            required: Some(false),
97            env_var: "FILETOOL_TOKEN".to_string(),
98            providers: vec![
99                AuthProvider {
100                    id: "github".to_string(),
101                    provider_type: "oauth2".to_string(),
102                    display_name: Some("GitHub".to_string()),
103                    authorization_url: Some(
104                        "https://github.com/login/oauth/authorize".to_string(),
105                    ),
106                    token_url: Some(
107                        "https://github.com/login/oauth/access_token".to_string(),
108                    ),
109                    scopes: Some(vec!["repo".to_string(), "read:user".to_string()]),
110                    client_id: Some("Ov23lixyz".to_string()),
111                    registration_url: None,
112                    instructions: None,
113                },
114                AuthProvider {
115                    id: "api-key".to_string(),
116                    provider_type: "api-key".to_string(),
117                    display_name: Some("API Key".to_string()),
118                    authorization_url: None,
119                    token_url: None,
120                    scopes: None,
121                    client_id: None,
122                    registration_url: Some("https://example.com/settings/keys".to_string()),
123                    instructions: Some(
124                        "Create a key at https://example.com/settings/keys".to_string(),
125                    ),
126                },
127            ],
128        })
129        .command_auth(
130            "process",
131            CommandAuth {
132                required: Some(true),
133                scopes: Some(vec!["write".to_string()]),
134            },
135        )
136        .parse();
137
138    match cli {
139        Cli::Convert {
140            input_file,
141            format,
142            pretty,
143        } => {
144            println!(
145                "Converting {} to {}{}",
146                input_file,
147                format,
148                if pretty { " (pretty)" } else { "" }
149            );
150        }
151        Cli::Validate {
152            input_file,
153            strict,
154        } => {
155            println!(
156                "Validating {}{}",
157                input_file,
158                if strict { " (strict)" } else { "" }
159            );
160        }
161        Cli::Process { verbose } => {
162            println!("Processing (verbose={})", verbose);
163        }
164    }
165}
Source

pub fn stdin( self, command_name: &str, content_type: &str, description: &str, ) -> Self

Examples found in repository?
examples/filetool.rs (lines 63-67)
49fn main() {
50    let cli: Cli = DescribableBuilder::new()
51        .example(
52            "convert",
53            "Convert a CSV file to JSON",
54            "filetool convert data.csv --format json --pretty",
55            Some("[{\n  \"name\": \"Alice\",\n  \"age\": 30\n}]"),
56        )
57        .example(
58            "convert",
59            "Pipe from stdin",
60            "cat data.csv | filetool convert - --format yaml",
61            None,
62        )
63        .stdin(
64            "convert",
65            "text/plain",
66            "Raw input data (alternative to file path)",
67        )
68        .stdout("convert", "application/json", "Converted output")
69        .example(
70            "validate",
71            "Validate a JSON file",
72            "filetool validate config.json",
73            Some("{\"valid\": true, \"errors\": []}"),
74        )
75        .example(
76            "process",
77            "Process a JSON object from stdin",
78            "echo '{\"name\":\"foo\",\"count\":3}' | filetool process",
79            Some("{\"status\": \"ok\", \"processed\": \"foo\"}"),
80        )
81        .stdin_with_schema(
82            "process",
83            "application/json",
84            "JSON object to process",
85            serde_json::json!({
86                "type": "object",
87                "properties": {
88                    "name": {"type": "string", "description": "Item name"},
89                    "count": {"type": "integer", "description": "Number of items"}
90                },
91                "required": ["name"]
92            }),
93        )
94        .stdout("process", "application/json", "Processing result")
95        .auth(AuthConfig {
96            required: Some(false),
97            env_var: "FILETOOL_TOKEN".to_string(),
98            providers: vec![
99                AuthProvider {
100                    id: "github".to_string(),
101                    provider_type: "oauth2".to_string(),
102                    display_name: Some("GitHub".to_string()),
103                    authorization_url: Some(
104                        "https://github.com/login/oauth/authorize".to_string(),
105                    ),
106                    token_url: Some(
107                        "https://github.com/login/oauth/access_token".to_string(),
108                    ),
109                    scopes: Some(vec!["repo".to_string(), "read:user".to_string()]),
110                    client_id: Some("Ov23lixyz".to_string()),
111                    registration_url: None,
112                    instructions: None,
113                },
114                AuthProvider {
115                    id: "api-key".to_string(),
116                    provider_type: "api-key".to_string(),
117                    display_name: Some("API Key".to_string()),
118                    authorization_url: None,
119                    token_url: None,
120                    scopes: None,
121                    client_id: None,
122                    registration_url: Some("https://example.com/settings/keys".to_string()),
123                    instructions: Some(
124                        "Create a key at https://example.com/settings/keys".to_string(),
125                    ),
126                },
127            ],
128        })
129        .command_auth(
130            "process",
131            CommandAuth {
132                required: Some(true),
133                scopes: Some(vec!["write".to_string()]),
134            },
135        )
136        .parse();
137
138    match cli {
139        Cli::Convert {
140            input_file,
141            format,
142            pretty,
143        } => {
144            println!(
145                "Converting {} to {}{}",
146                input_file,
147                format,
148                if pretty { " (pretty)" } else { "" }
149            );
150        }
151        Cli::Validate {
152            input_file,
153            strict,
154        } => {
155            println!(
156                "Validating {}{}",
157                input_file,
158                if strict { " (strict)" } else { "" }
159            );
160        }
161        Cli::Process { verbose } => {
162            println!("Processing (verbose={})", verbose);
163        }
164    }
165}
Source

pub fn stdout( self, command_name: &str, content_type: &str, description: &str, ) -> Self

Examples found in repository?
examples/filetool.rs (line 68)
49fn main() {
50    let cli: Cli = DescribableBuilder::new()
51        .example(
52            "convert",
53            "Convert a CSV file to JSON",
54            "filetool convert data.csv --format json --pretty",
55            Some("[{\n  \"name\": \"Alice\",\n  \"age\": 30\n}]"),
56        )
57        .example(
58            "convert",
59            "Pipe from stdin",
60            "cat data.csv | filetool convert - --format yaml",
61            None,
62        )
63        .stdin(
64            "convert",
65            "text/plain",
66            "Raw input data (alternative to file path)",
67        )
68        .stdout("convert", "application/json", "Converted output")
69        .example(
70            "validate",
71            "Validate a JSON file",
72            "filetool validate config.json",
73            Some("{\"valid\": true, \"errors\": []}"),
74        )
75        .example(
76            "process",
77            "Process a JSON object from stdin",
78            "echo '{\"name\":\"foo\",\"count\":3}' | filetool process",
79            Some("{\"status\": \"ok\", \"processed\": \"foo\"}"),
80        )
81        .stdin_with_schema(
82            "process",
83            "application/json",
84            "JSON object to process",
85            serde_json::json!({
86                "type": "object",
87                "properties": {
88                    "name": {"type": "string", "description": "Item name"},
89                    "count": {"type": "integer", "description": "Number of items"}
90                },
91                "required": ["name"]
92            }),
93        )
94        .stdout("process", "application/json", "Processing result")
95        .auth(AuthConfig {
96            required: Some(false),
97            env_var: "FILETOOL_TOKEN".to_string(),
98            providers: vec![
99                AuthProvider {
100                    id: "github".to_string(),
101                    provider_type: "oauth2".to_string(),
102                    display_name: Some("GitHub".to_string()),
103                    authorization_url: Some(
104                        "https://github.com/login/oauth/authorize".to_string(),
105                    ),
106                    token_url: Some(
107                        "https://github.com/login/oauth/access_token".to_string(),
108                    ),
109                    scopes: Some(vec!["repo".to_string(), "read:user".to_string()]),
110                    client_id: Some("Ov23lixyz".to_string()),
111                    registration_url: None,
112                    instructions: None,
113                },
114                AuthProvider {
115                    id: "api-key".to_string(),
116                    provider_type: "api-key".to_string(),
117                    display_name: Some("API Key".to_string()),
118                    authorization_url: None,
119                    token_url: None,
120                    scopes: None,
121                    client_id: None,
122                    registration_url: Some("https://example.com/settings/keys".to_string()),
123                    instructions: Some(
124                        "Create a key at https://example.com/settings/keys".to_string(),
125                    ),
126                },
127            ],
128        })
129        .command_auth(
130            "process",
131            CommandAuth {
132                required: Some(true),
133                scopes: Some(vec!["write".to_string()]),
134            },
135        )
136        .parse();
137
138    match cli {
139        Cli::Convert {
140            input_file,
141            format,
142            pretty,
143        } => {
144            println!(
145                "Converting {} to {}{}",
146                input_file,
147                format,
148                if pretty { " (pretty)" } else { "" }
149            );
150        }
151        Cli::Validate {
152            input_file,
153            strict,
154        } => {
155            println!(
156                "Validating {}{}",
157                input_file,
158                if strict { " (strict)" } else { "" }
159            );
160        }
161        Cli::Process { verbose } => {
162            println!("Processing (verbose={})", verbose);
163        }
164    }
165}
Source

pub fn stdin_with_schema( self, command_name: &str, content_type: &str, description: &str, schema: Value, ) -> Self

Examples found in repository?
examples/filetool.rs (lines 81-93)
49fn main() {
50    let cli: Cli = DescribableBuilder::new()
51        .example(
52            "convert",
53            "Convert a CSV file to JSON",
54            "filetool convert data.csv --format json --pretty",
55            Some("[{\n  \"name\": \"Alice\",\n  \"age\": 30\n}]"),
56        )
57        .example(
58            "convert",
59            "Pipe from stdin",
60            "cat data.csv | filetool convert - --format yaml",
61            None,
62        )
63        .stdin(
64            "convert",
65            "text/plain",
66            "Raw input data (alternative to file path)",
67        )
68        .stdout("convert", "application/json", "Converted output")
69        .example(
70            "validate",
71            "Validate a JSON file",
72            "filetool validate config.json",
73            Some("{\"valid\": true, \"errors\": []}"),
74        )
75        .example(
76            "process",
77            "Process a JSON object from stdin",
78            "echo '{\"name\":\"foo\",\"count\":3}' | filetool process",
79            Some("{\"status\": \"ok\", \"processed\": \"foo\"}"),
80        )
81        .stdin_with_schema(
82            "process",
83            "application/json",
84            "JSON object to process",
85            serde_json::json!({
86                "type": "object",
87                "properties": {
88                    "name": {"type": "string", "description": "Item name"},
89                    "count": {"type": "integer", "description": "Number of items"}
90                },
91                "required": ["name"]
92            }),
93        )
94        .stdout("process", "application/json", "Processing result")
95        .auth(AuthConfig {
96            required: Some(false),
97            env_var: "FILETOOL_TOKEN".to_string(),
98            providers: vec![
99                AuthProvider {
100                    id: "github".to_string(),
101                    provider_type: "oauth2".to_string(),
102                    display_name: Some("GitHub".to_string()),
103                    authorization_url: Some(
104                        "https://github.com/login/oauth/authorize".to_string(),
105                    ),
106                    token_url: Some(
107                        "https://github.com/login/oauth/access_token".to_string(),
108                    ),
109                    scopes: Some(vec!["repo".to_string(), "read:user".to_string()]),
110                    client_id: Some("Ov23lixyz".to_string()),
111                    registration_url: None,
112                    instructions: None,
113                },
114                AuthProvider {
115                    id: "api-key".to_string(),
116                    provider_type: "api-key".to_string(),
117                    display_name: Some("API Key".to_string()),
118                    authorization_url: None,
119                    token_url: None,
120                    scopes: None,
121                    client_id: None,
122                    registration_url: Some("https://example.com/settings/keys".to_string()),
123                    instructions: Some(
124                        "Create a key at https://example.com/settings/keys".to_string(),
125                    ),
126                },
127            ],
128        })
129        .command_auth(
130            "process",
131            CommandAuth {
132                required: Some(true),
133                scopes: Some(vec!["write".to_string()]),
134            },
135        )
136        .parse();
137
138    match cli {
139        Cli::Convert {
140            input_file,
141            format,
142            pretty,
143        } => {
144            println!(
145                "Converting {} to {}{}",
146                input_file,
147                format,
148                if pretty { " (pretty)" } else { "" }
149            );
150        }
151        Cli::Validate {
152            input_file,
153            strict,
154        } => {
155            println!(
156                "Validating {}{}",
157                input_file,
158                if strict { " (strict)" } else { "" }
159            );
160        }
161        Cli::Process { verbose } => {
162            println!("Processing (verbose={})", verbose);
163        }
164    }
165}
Source

pub fn stdout_with_schema( self, command_name: &str, content_type: &str, description: &str, schema: Value, ) -> Self

Source

pub fn auth(self, config: AuthConfig) -> Self

Set tool-level auth configuration.

Examples found in repository?
examples/filetool.rs (lines 95-128)
49fn main() {
50    let cli: Cli = DescribableBuilder::new()
51        .example(
52            "convert",
53            "Convert a CSV file to JSON",
54            "filetool convert data.csv --format json --pretty",
55            Some("[{\n  \"name\": \"Alice\",\n  \"age\": 30\n}]"),
56        )
57        .example(
58            "convert",
59            "Pipe from stdin",
60            "cat data.csv | filetool convert - --format yaml",
61            None,
62        )
63        .stdin(
64            "convert",
65            "text/plain",
66            "Raw input data (alternative to file path)",
67        )
68        .stdout("convert", "application/json", "Converted output")
69        .example(
70            "validate",
71            "Validate a JSON file",
72            "filetool validate config.json",
73            Some("{\"valid\": true, \"errors\": []}"),
74        )
75        .example(
76            "process",
77            "Process a JSON object from stdin",
78            "echo '{\"name\":\"foo\",\"count\":3}' | filetool process",
79            Some("{\"status\": \"ok\", \"processed\": \"foo\"}"),
80        )
81        .stdin_with_schema(
82            "process",
83            "application/json",
84            "JSON object to process",
85            serde_json::json!({
86                "type": "object",
87                "properties": {
88                    "name": {"type": "string", "description": "Item name"},
89                    "count": {"type": "integer", "description": "Number of items"}
90                },
91                "required": ["name"]
92            }),
93        )
94        .stdout("process", "application/json", "Processing result")
95        .auth(AuthConfig {
96            required: Some(false),
97            env_var: "FILETOOL_TOKEN".to_string(),
98            providers: vec![
99                AuthProvider {
100                    id: "github".to_string(),
101                    provider_type: "oauth2".to_string(),
102                    display_name: Some("GitHub".to_string()),
103                    authorization_url: Some(
104                        "https://github.com/login/oauth/authorize".to_string(),
105                    ),
106                    token_url: Some(
107                        "https://github.com/login/oauth/access_token".to_string(),
108                    ),
109                    scopes: Some(vec!["repo".to_string(), "read:user".to_string()]),
110                    client_id: Some("Ov23lixyz".to_string()),
111                    registration_url: None,
112                    instructions: None,
113                },
114                AuthProvider {
115                    id: "api-key".to_string(),
116                    provider_type: "api-key".to_string(),
117                    display_name: Some("API Key".to_string()),
118                    authorization_url: None,
119                    token_url: None,
120                    scopes: None,
121                    client_id: None,
122                    registration_url: Some("https://example.com/settings/keys".to_string()),
123                    instructions: Some(
124                        "Create a key at https://example.com/settings/keys".to_string(),
125                    ),
126                },
127            ],
128        })
129        .command_auth(
130            "process",
131            CommandAuth {
132                required: Some(true),
133                scopes: Some(vec!["write".to_string()]),
134            },
135        )
136        .parse();
137
138    match cli {
139        Cli::Convert {
140            input_file,
141            format,
142            pretty,
143        } => {
144            println!(
145                "Converting {} to {}{}",
146                input_file,
147                format,
148                if pretty { " (pretty)" } else { "" }
149            );
150        }
151        Cli::Validate {
152            input_file,
153            strict,
154        } => {
155            println!(
156                "Validating {}{}",
157                input_file,
158                if strict { " (strict)" } else { "" }
159            );
160        }
161        Cli::Process { verbose } => {
162            println!("Processing (verbose={})", verbose);
163        }
164    }
165}
Source

pub fn command_auth(self, command_name: &str, auth: CommandAuth) -> Self

Set per-command auth overrides.

Examples found in repository?
examples/filetool.rs (lines 129-135)
49fn main() {
50    let cli: Cli = DescribableBuilder::new()
51        .example(
52            "convert",
53            "Convert a CSV file to JSON",
54            "filetool convert data.csv --format json --pretty",
55            Some("[{\n  \"name\": \"Alice\",\n  \"age\": 30\n}]"),
56        )
57        .example(
58            "convert",
59            "Pipe from stdin",
60            "cat data.csv | filetool convert - --format yaml",
61            None,
62        )
63        .stdin(
64            "convert",
65            "text/plain",
66            "Raw input data (alternative to file path)",
67        )
68        .stdout("convert", "application/json", "Converted output")
69        .example(
70            "validate",
71            "Validate a JSON file",
72            "filetool validate config.json",
73            Some("{\"valid\": true, \"errors\": []}"),
74        )
75        .example(
76            "process",
77            "Process a JSON object from stdin",
78            "echo '{\"name\":\"foo\",\"count\":3}' | filetool process",
79            Some("{\"status\": \"ok\", \"processed\": \"foo\"}"),
80        )
81        .stdin_with_schema(
82            "process",
83            "application/json",
84            "JSON object to process",
85            serde_json::json!({
86                "type": "object",
87                "properties": {
88                    "name": {"type": "string", "description": "Item name"},
89                    "count": {"type": "integer", "description": "Number of items"}
90                },
91                "required": ["name"]
92            }),
93        )
94        .stdout("process", "application/json", "Processing result")
95        .auth(AuthConfig {
96            required: Some(false),
97            env_var: "FILETOOL_TOKEN".to_string(),
98            providers: vec![
99                AuthProvider {
100                    id: "github".to_string(),
101                    provider_type: "oauth2".to_string(),
102                    display_name: Some("GitHub".to_string()),
103                    authorization_url: Some(
104                        "https://github.com/login/oauth/authorize".to_string(),
105                    ),
106                    token_url: Some(
107                        "https://github.com/login/oauth/access_token".to_string(),
108                    ),
109                    scopes: Some(vec!["repo".to_string(), "read:user".to_string()]),
110                    client_id: Some("Ov23lixyz".to_string()),
111                    registration_url: None,
112                    instructions: None,
113                },
114                AuthProvider {
115                    id: "api-key".to_string(),
116                    provider_type: "api-key".to_string(),
117                    display_name: Some("API Key".to_string()),
118                    authorization_url: None,
119                    token_url: None,
120                    scopes: None,
121                    client_id: None,
122                    registration_url: Some("https://example.com/settings/keys".to_string()),
123                    instructions: Some(
124                        "Create a key at https://example.com/settings/keys".to_string(),
125                    ),
126                },
127            ],
128        })
129        .command_auth(
130            "process",
131            CommandAuth {
132                required: Some(true),
133                scopes: Some(vec!["write".to_string()]),
134            },
135        )
136        .parse();
137
138    match cli {
139        Cli::Convert {
140            input_file,
141            format,
142            pretty,
143        } => {
144            println!(
145                "Converting {} to {}{}",
146                input_file,
147                format,
148                if pretty { " (pretty)" } else { "" }
149            );
150        }
151        Cli::Validate {
152            input_file,
153            strict,
154        } => {
155            println!(
156                "Validating {}{}",
157                input_file,
158                if strict { " (strict)" } else { "" }
159            );
160        }
161        Cli::Process { verbose } => {
162            println!("Processing (verbose={})", verbose);
163        }
164    }
165}
Source

pub fn parse<T: Parser>(self) -> T

Check for --mtp-describe (printing schema + exiting if present), otherwise parse and return the CLI struct.

If a subcommand name appears in argv alongside --mtp-describe, the flag is NOT intercepted here; the subcommand is expected to handle it (e.g. wrap --mtp-describe means “describe the wrapped server”, not “describe this CLI”).

Examples found in repository?
examples/filetool.rs (line 136)
49fn main() {
50    let cli: Cli = DescribableBuilder::new()
51        .example(
52            "convert",
53            "Convert a CSV file to JSON",
54            "filetool convert data.csv --format json --pretty",
55            Some("[{\n  \"name\": \"Alice\",\n  \"age\": 30\n}]"),
56        )
57        .example(
58            "convert",
59            "Pipe from stdin",
60            "cat data.csv | filetool convert - --format yaml",
61            None,
62        )
63        .stdin(
64            "convert",
65            "text/plain",
66            "Raw input data (alternative to file path)",
67        )
68        .stdout("convert", "application/json", "Converted output")
69        .example(
70            "validate",
71            "Validate a JSON file",
72            "filetool validate config.json",
73            Some("{\"valid\": true, \"errors\": []}"),
74        )
75        .example(
76            "process",
77            "Process a JSON object from stdin",
78            "echo '{\"name\":\"foo\",\"count\":3}' | filetool process",
79            Some("{\"status\": \"ok\", \"processed\": \"foo\"}"),
80        )
81        .stdin_with_schema(
82            "process",
83            "application/json",
84            "JSON object to process",
85            serde_json::json!({
86                "type": "object",
87                "properties": {
88                    "name": {"type": "string", "description": "Item name"},
89                    "count": {"type": "integer", "description": "Number of items"}
90                },
91                "required": ["name"]
92            }),
93        )
94        .stdout("process", "application/json", "Processing result")
95        .auth(AuthConfig {
96            required: Some(false),
97            env_var: "FILETOOL_TOKEN".to_string(),
98            providers: vec![
99                AuthProvider {
100                    id: "github".to_string(),
101                    provider_type: "oauth2".to_string(),
102                    display_name: Some("GitHub".to_string()),
103                    authorization_url: Some(
104                        "https://github.com/login/oauth/authorize".to_string(),
105                    ),
106                    token_url: Some(
107                        "https://github.com/login/oauth/access_token".to_string(),
108                    ),
109                    scopes: Some(vec!["repo".to_string(), "read:user".to_string()]),
110                    client_id: Some("Ov23lixyz".to_string()),
111                    registration_url: None,
112                    instructions: None,
113                },
114                AuthProvider {
115                    id: "api-key".to_string(),
116                    provider_type: "api-key".to_string(),
117                    display_name: Some("API Key".to_string()),
118                    authorization_url: None,
119                    token_url: None,
120                    scopes: None,
121                    client_id: None,
122                    registration_url: Some("https://example.com/settings/keys".to_string()),
123                    instructions: Some(
124                        "Create a key at https://example.com/settings/keys".to_string(),
125                    ),
126                },
127            ],
128        })
129        .command_auth(
130            "process",
131            CommandAuth {
132                required: Some(true),
133                scopes: Some(vec!["write".to_string()]),
134            },
135        )
136        .parse();
137
138    match cli {
139        Cli::Convert {
140            input_file,
141            format,
142            pretty,
143        } => {
144            println!(
145                "Converting {} to {}{}",
146                input_file,
147                format,
148                if pretty { " (pretty)" } else { "" }
149            );
150        }
151        Cli::Validate {
152            input_file,
153            strict,
154        } => {
155            println!(
156                "Validating {}{}",
157                input_file,
158                if strict { " (strict)" } else { "" }
159            );
160        }
161        Cli::Process { verbose } => {
162            println!("Processing (verbose={})", verbose);
163        }
164    }
165}
Source

pub fn schema<T: CommandFactory>(&self) -> ToolSchema

Generate schema without side effects. For testing.

Trait Implementations§

Source§

impl Default for DescribableBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.