@@ -124,40 +124,8 @@ fn run() -> anyhow::Result<()> {
124
124
} )
125
125
. collect :: < Vec < _ > > ( ) ;
126
126
log:: trace!( "CLI args: {env_args:#?}" ) ;
127
- let cli = Cli :: parse_from ( env_args. clone ( ) ) ;
128
-
129
- match cli. command {
130
- Command :: Install ( install) => {
131
- let shader_crate_path = install. shader_crate ;
132
- let command =
133
- config:: Config :: clap_command_with_cargo_config ( & shader_crate_path, env_args) ?;
134
- log:: debug!(
135
- "installing with final merged arguments: {:#?}" ,
136
- command. install
137
- ) ;
138
- command. install . run ( ) ?;
139
- }
140
- Command :: Build ( build) => {
141
- let shader_crate_path = build. install . shader_crate ;
142
- let mut command =
143
- config:: Config :: clap_command_with_cargo_config ( & shader_crate_path, env_args) ?;
144
- log:: debug!( "building with final merged arguments: {command:#?}" ) ;
145
-
146
- if command. build . watch {
147
- // When watching, do one normal run to setup the `manifest.json` file.
148
- command. build . watch = false ;
149
- command. run ( ) ?;
150
- command. build . watch = true ;
151
- command. run ( ) ?;
152
- } else {
153
- command. run ( ) ?;
154
- }
155
- }
156
- Command :: Show ( show) => show. run ( ) ?,
157
- Command :: DumpUsage => dump_full_usage_for_readme ( ) ?,
158
- }
159
-
160
- Ok ( ( ) )
127
+ let cli = Cli :: parse_from ( & env_args) ;
128
+ cli. command . run ( env_args)
161
129
}
162
130
163
131
/// All of the available subcommands for `cargo gpu`
@@ -179,6 +147,45 @@ enum Command {
179
147
DumpUsage ,
180
148
}
181
149
150
+ impl Command {
151
+ /// run the command
152
+ pub fn run ( & self , env_args : Vec < String > ) -> anyhow:: Result < ( ) > {
153
+ match & self {
154
+ Self :: Install ( install) => {
155
+ let shader_crate_path = & install. shader_crate ;
156
+ let command =
157
+ config:: Config :: clap_command_with_cargo_config ( shader_crate_path, env_args) ?;
158
+ log:: debug!(
159
+ "installing with final merged arguments: {:#?}" ,
160
+ command. install
161
+ ) ;
162
+ command. install . run ( ) ?;
163
+ }
164
+ Self :: Build ( build) => {
165
+ let shader_crate_path = & build. install . shader_crate ;
166
+ let mut command =
167
+ config:: Config :: clap_command_with_cargo_config ( shader_crate_path, env_args) ?;
168
+ log:: debug!( "building with final merged arguments: {command:#?}" ) ;
169
+
170
+ if command. build . watch {
171
+ // When watching, do one normal run to setup the `manifest.json` file.
172
+ command. build . watch = false ;
173
+ command. run ( ) ?;
174
+ command. build . watch = true ;
175
+ command. run ( ) ?;
176
+ } else {
177
+ command. run ( ) ?;
178
+ }
179
+ }
180
+ Self :: Show ( show) => show. run ( ) ?,
181
+ Self :: DumpUsage => dump_full_usage_for_readme ( ) ?,
182
+ }
183
+
184
+ Ok ( ( ) )
185
+ }
186
+ }
187
+
188
+ /// the Cli struct representing the main cli
182
189
#[ derive( clap:: Parser ) ]
183
190
#[ clap( author, version, about, subcommand_required = true ) ]
184
191
pub ( crate ) struct Cli {
0 commit comments