11use std:: { error:: Error , path:: PathBuf } ;
22
3- use clap:: { Parser , Subcommand , builder:: TypedValueParser } ;
3+ use clap:: { Args , Parser , Subcommand , builder:: TypedValueParser } ;
44use strum:: VariantNames ;
55
66use crate :: {
77 config:: { ComputePlatform , get_config_dir, get_data_dir, get_project_local_config_file} ,
8+ cscs:: api_client:: client:: { EdfSpec as EdfSpecEnum , ScriptSpec as ScriptSpecEnum } ,
89 util:: types:: DockerImageUrl ,
910} ;
1011
@@ -56,6 +57,77 @@ pub enum CscsCommands {
5657 } ,
5758}
5859
60+ #[ derive( Args , Clone , Debug ) ]
61+ #[ group( multiple = false ) ]
62+ pub struct ScriptSpec {
63+ #[ arg(
64+ long,
65+ help = "generate and upload script file based on template (on by default unless `--local` or `--remote` are passed)"
66+ ) ]
67+ generate_script : bool ,
68+ #[ arg( long, value_name = "PATH" , help = "upload local script file" ) ]
69+ local_script : Option < PathBuf > ,
70+ #[ arg( long, value_name = "PATH" , help = "use script file already present on remote" ) ]
71+ remote_script : Option < PathBuf > ,
72+ }
73+ impl Default for ScriptSpec {
74+ fn default ( ) -> Self {
75+ Self {
76+ generate_script : true ,
77+ local_script : Default :: default ( ) ,
78+ remote_script : Default :: default ( ) ,
79+ }
80+ }
81+ }
82+
83+ impl From < ScriptSpec > for ScriptSpecEnum {
84+ fn from ( val : ScriptSpec ) -> Self {
85+ if let Some ( local_script) = val. local_script {
86+ ScriptSpecEnum :: Local ( local_script)
87+ } else if let Some ( remote_script) = val. remote_script {
88+ ScriptSpecEnum :: Remote ( remote_script)
89+ } else {
90+ ScriptSpecEnum :: Generate
91+ }
92+ }
93+ }
94+
95+ #[ derive( Args , Clone , Debug ) ]
96+ #[ group( multiple = false ) ]
97+ pub struct EdfSpec {
98+ #[ arg(
99+ long,
100+ help = "generate and upload edf file based on template (on by default unless `--local` or `--remote` are passed)"
101+ ) ]
102+ generate_edf : bool ,
103+ #[ arg( long, value_name = "PATH" , help = "upload local edf file" ) ]
104+ local_edf : Option < PathBuf > ,
105+ #[ arg( long, value_name = "PATH" , help = "use edf file already present on remote" ) ]
106+ remote_edf : Option < PathBuf > ,
107+ }
108+
109+ impl Default for EdfSpec {
110+ fn default ( ) -> Self {
111+ Self {
112+ generate_edf : true ,
113+ local_edf : Default :: default ( ) ,
114+ remote_edf : Default :: default ( ) ,
115+ }
116+ }
117+ }
118+
119+ impl From < EdfSpec > for EdfSpecEnum {
120+ fn from ( val : EdfSpec ) -> Self {
121+ if let Some ( local_edf) = val. local_edf {
122+ EdfSpecEnum :: Local ( local_edf)
123+ } else if let Some ( remote_edf) = val. remote_edf {
124+ EdfSpecEnum :: Remote ( remote_edf)
125+ } else {
126+ EdfSpecEnum :: Generate
127+ }
128+ }
129+ }
130+
59131#[ allow( clippy:: large_enum_variant) ]
60132#[ derive( Subcommand , Debug ) ]
61133pub enum CscsJobCommands {
@@ -74,8 +146,6 @@ pub enum CscsJobCommands {
74146 Submit {
75147 #[ clap( short, long, help = "name of the job" ) ]
76148 name : Option < String > ,
77- #[ clap( short, long, help = "the path to the srun script file to use" ) ]
78- script_file : Option < PathBuf > ,
79149 #[ clap(
80150 short,
81151 long,
@@ -88,10 +158,14 @@ pub enum CscsJobCommands {
88158 mount : Vec < ( String , String ) > ,
89159 #[ clap( short, long, help = "The docker image to use" ) ]
90160 image : Option < DockerImageUrl > ,
91- #[ clap( short , long, help = "Path where stdout of the job gets written to" ) ]
161+ #[ clap( long, help = "Path where stdout of the job gets written to" ) ]
92162 stdout : Option < PathBuf > ,
93- #[ clap( short , long, help = "Path where stderr of the job gets written to" ) ]
163+ #[ clap( long, help = "Path where stderr of the job gets written to" ) ]
94164 stderr : Option < PathBuf > ,
165+ #[ command( flatten) ]
166+ edf_spec : Option < EdfSpec > ,
167+ #[ command( flatten) ]
168+ script_spec : Option < ScriptSpec > ,
95169 #[ clap( trailing_var_arg = true , help = "The command to run in the container" ) ]
96170 command : Option < Vec < String > > ,
97171 } ,
0 commit comments