@@ -20,82 +20,16 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
2020//!
2121//! This module defines the command-line arguments and behavior of `newdoc`.
2222//! It relies on the `clap` crate.
23- use clap:: { command, Arg , ArgGroup , ArgMatches } ;
2423
25- /// Define the command-line arguments and return them as the `clap::ArgMatches` struct.
26- #[ must_use]
27- pub fn get_args ( ) -> ArgMatches {
28- // Define command-line options
29- let matches = command ! ( )
30- // If no arguments are provided, print help
31- . arg_required_else_help ( true )
32- . arg (
33- Arg :: new ( "assembly" )
34- . short ( 'a' )
35- . long ( "assembly" )
36- . takes_value ( true )
37- . value_name ( "title" )
38- . multiple_occurrences ( true )
39- . help ( "Create an assembly file" ) ,
40- )
41- . arg (
42- Arg :: new ( "include-in" )
43- . short ( 'i' )
44- . long ( "include-in" )
45- . takes_value ( true )
46- . value_name ( "title" )
47- . multiple_occurrences ( false )
48- . help ( "Create an assembly that includes the other specified modules" ) ,
49- )
50- . arg (
51- Arg :: new ( "concept" )
52- . short ( 'c' )
53- . long ( "concept" )
54- . takes_value ( true )
55- . value_name ( "title" )
56- . multiple_occurrences ( true )
57- . help ( "Create a concept module" ) ,
58- )
59- . arg (
60- Arg :: new ( "procedure" )
61- . short ( 'p' )
62- . long ( "procedure" )
63- . takes_value ( true )
64- . value_name ( "title" )
65- . multiple_occurrences ( true )
66- . help ( "Create a procedure module" ) ,
67- )
68- . arg (
69- Arg :: new ( "reference" )
70- . short ( 'r' )
71- . long ( "reference" )
72- . takes_value ( true )
73- . value_name ( "title" )
74- . multiple_occurrences ( true )
75- . help ( "Create a reference module" ) ,
76- )
77- . arg (
78- Arg :: new ( "snippet" )
79- . short ( 's' )
80- . long ( "snippet" )
81- . takes_value ( true )
82- . value_name ( "title" )
83- . multiple_occurrences ( true )
84- . help ( "Create a snippet file" ) ,
85- )
86- . arg (
87- Arg :: new ( "validate" )
88- . short ( 'l' )
89- . long ( "validate" )
90- . takes_value ( true )
91- . value_name ( "file" )
92- . multiple_values ( true )
93- . help ( "Validate (lint) an existing module or assembly file" ) ,
94- )
95- // This group specifies that you either generate modules or validate existing ones
96- . group (
97- ArgGroup :: new ( "required" )
98- . args ( & [
24+ use std:: path:: PathBuf ;
25+
26+ use clap:: { ArgGroup , Parser } ;
27+
28+ #[ derive( Parser ) ]
29+ #[ command( author, version, about, long_about = None , arg_required_else_help( true ) ) ]
30+ #[ command( group(
31+ ArgGroup :: new( "required" )
32+ . args( [
9933 "assembly" ,
10034 "concept" ,
10135 "procedure" ,
@@ -104,50 +38,64 @@ pub fn get_args() -> ArgMatches {
10438 "validate" ,
10539 ] )
10640 . required( true )
107- . multiple ( true ) ,
108- )
109- . arg (
110- Arg :: new ( "no-comments" )
111- . short ( 'C' )
112- . long ( "no-comments" )
113- . help ( "Generate the file without any comments" ) ,
114- )
115- . arg (
116- Arg :: new ( "no-examples" )
117- . short ( 'E' )
118- . long ( "no-examples" )
119- . alias ( "expert-mode" )
120- . help ( "Generate the file without any example, placeholder content" ) ,
121- )
122- . arg (
123- Arg :: new ( "no-prefixes" )
124- . short ( 'P' )
125- . long ( "no-prefixes" )
126- . help ( "Do not use module type prefixes (such as `proc_`) in IDs and file names" ) ,
127- )
128- . arg (
129- Arg :: new ( "target-dir" )
130- . short ( 'T' )
131- . long ( "target-dir" )
132- . takes_value ( true )
133- . value_name ( "directory" )
134- . help ( "Save the generated files in this directory" ) ,
135- )
136- . arg (
137- Arg :: new ( "verbose" )
138- . short ( 'v' )
139- . long ( "verbose" )
140- . help ( "Display additional, debug messages" )
141- . conflicts_with ( "quiet" ) ,
142- )
143- . arg (
144- Arg :: new ( "quiet" )
145- . short ( 'q' )
146- . long ( "quiet" )
147- . help ( "Hide info-level messages. Display only warnings and errors" )
148- . conflicts_with ( "verbose" ) ,
149- )
150- . get_matches ( ) ;
151-
152- matches
41+ . multiple( true )
42+ ) ) ]
43+ pub struct Cli {
44+ /// Create an assembly file
45+ #[ arg( short, long, value_name = "TITLE" ) ]
46+ pub assembly : Option < Vec < String > > ,
47+
48+ /// Create an assembly that includes the other specified modules
49+ #[ arg( short, long = "include-in" , value_name = "TITLE" ) ]
50+ pub include_in : Option < String > ,
51+
52+ /// Create a concept module
53+ #[ arg( short, long, value_name = "TITLE" ) ]
54+ pub concept : Option < Vec < String > > ,
55+
56+ /// Create a procedure module
57+ #[ arg( short, long, value_name = "TITLE" ) ]
58+ pub procedure : Option < Vec < String > > ,
59+
60+ /// Create a reference module
61+ #[ arg( short, long, value_name = "TITLE" ) ]
62+ pub reference : Option < Vec < String > > ,
63+
64+ /// Create a snippet file
65+ #[ arg( short, long, value_name = "TITLE" ) ]
66+ pub snippet : Option < Vec < String > > ,
67+
68+ /// Validate (lint) an existing module or assembly file
69+ #[ arg( short = 'l' , long, value_name = "FILE" ) ]
70+ pub validate : Option < Vec < PathBuf > > ,
71+
72+ /// Generate the file without any comments
73+ #[ arg( short = 'C' , long = "no-comments" ) ]
74+ pub no_comments : bool ,
75+
76+ /// Generate the file without any example, placeholder content
77+ #[ arg( short = 'E' , long = "no-examples" , alias = "expert-mode" ) ]
78+ pub no_examples : bool ,
79+
80+ /// Do not use module type prefixes (such as `proc_`) in IDs and file names
81+ #[ arg( short = 'P' , long = "no-prefixes" ) ]
82+ pub no_prefixes : bool ,
83+
84+ /// Save the generated files in this directory
85+ #[ arg( short = 'T' , long = "target-dir" , value_name = "DIRECTORY" ) ]
86+ pub target_dir : Option < PathBuf > ,
87+
88+ /// Display additional, debug messages
89+ #[ arg( short, long, conflicts_with = "quiet" ) ]
90+ pub verbose : bool ,
91+
92+ /// Hide info-level messages. Display only warnings and errors
93+ #[ arg( short, long, conflicts_with = "verbose" ) ]
94+ pub quiet : bool ,
95+ }
96+
97+ /// Get command-line arguments as the `Cli` struct.
98+ #[ must_use]
99+ pub fn get_args ( ) -> Cli {
100+ Cli :: parse ( )
153101}
0 commit comments