1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
use clap::{Parser, Subcommand};
use chris::types::{CubeUrl, Username};
use crate::arg::GivenDataNode;
use crate::cd::cd;
use crate::credentials::Credentials;
use crate::describe::{describe_runnable, DescribeArgs};
use crate::download::{download, DownloadArgs};
use crate::list::{list_feeds, ListFeedArgs};
use crate::login::cmd::{login, logout};
use crate::login::store::Backend;
use crate::login::switch::switch_login;
use crate::login::UiUrl;
use crate::logs::logs;
use crate::ls::{ls, LsArgs};
use crate::run::{run_command, RunArgs};
use crate::search::{search_runnable, SearchArgs};
use crate::status::cmd::status;
use crate::upload::{upload, UploadArgs};
use crate::whoami::whoami;
mod arg;
mod cd;
mod credentials;
mod describe;
mod download;
mod error_messages;
mod file_transfer;
mod files;
mod list;
mod login;
mod logs;
mod ls;
mod plugin_clap;
mod run;
mod search;
mod shlex;
mod status;
pub mod unicode;
mod upload;
mod whoami;
#[derive(Parser)]
#[clap(
version,
about = "ChRIS Research Integration System -- command line client",
propagate_version = false,
disable_help_subcommand = true
)]
struct Cli {
/// ChRIS backend API URL
#[clap(long, global = true)]
cube: Option<CubeUrl>,
/// ChRIS_ui URL
#[clap(long, global = true)]
ui: Option<UiUrl>,
/// account username
#[clap(long, global = true)]
username: Option<Username>,
/// account password
#[clap(long, global = true)]
password: Option<String>,
/// authorization token
#[clap(long, global = true)]
token: Option<String>,
/// Number of times to retry HTTP requests
#[clap(long)]
retries: Option<u32>,
#[clap(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
/// Remember login account
///
/// Stores a username and authorization token for a given ChRIS API URL.
Login {
/// Save token in plaintext instead of using keyring
#[clap(long)]
no_keyring: bool,
/// Take the password from stdin
#[clap(long)]
password_stdin: bool,
},
/// Remove a user session
Logout {},
/// Switch user
Switch {},
/// Show login information
Whoami {},
/// List files
Ls(LsArgs),
/// List feeds
List(ListFeedArgs),
/// Search for plugins and pipelines
Search(SearchArgs),
/// Change plugin instance context
Cd {
/// Plugin instance to switch to.
///
/// The value can be a plugin instance ID or title. For a title,
/// the title must be unique within the search space. The current
/// feed will be searched before searching across all feeds.
plugin_instance: GivenDataNode,
},
/// Show status of a feed branch
Status {
/// Print plugin execshell and selfpath
#[clap(short, long)]
execshell: bool,
/// Feed or plugin instance
feed_or_plugin_instance: Option<GivenDataNode>,
},
/// Show the logs of a plugin instance
Logs {
/// Plugin instance
plugin_instance: Option<GivenDataNode>,
},
/// Describe and get usage of a plugin or pipeline
Describe(DescribeArgs),
/// Run a plugin or pipeline
Run(RunArgs),
/// Upload files to ChRIS
Upload(UploadArgs),
/// Download files from ChRIS
Download(DownloadArgs),
// /// Get detailed information about a ChRIS object
// ///
// /// An object may be a plugin, plugin instance, pipeline, feed, or file.
// // Future work: also support PACS files
// Describe(String),
//
// /// Run a plugin or pipeline
// // TODO: can also create feed and upload files
// Run { },
// Future work
// /// Set name or title of a feed or plugin instance
// Set {},
// /// Upload files and run workflows
// Upload {
// /// Path prefix, i.e. subdir of <username>/uploads to upload to
// #[clap(short='P', long, default_value_t=String::from(""))]
// path: String,
//
// /// Create a feed with a name
// #[clap(short, long)]
// feed: Option<String>,
//
// /// Run a pipeline
// #[clap(short = 'p', long)]
// pipeline: Option<String>,
//
// /// Files and directories to upload
// #[clap(required = true)]
// files: Vec<PathBuf>,
// },
//
}
#[tokio::main]
async fn main() -> color_eyre::eyre::Result<()> {
#[cfg(debug_assertions)]
color_eyre::install()?;
#[cfg(not(debug_assertions))]
color_eyre::config::HookBuilder::default()
// .issue_url(concat!(env!("CARGO_PKG_REPOSITORY"), "/issues/new"))
// .add_issue_metadata("version", env!("CARGO_PKG_VERSION"))
.display_location_section(false)
.install()?;
let args: Cli = Cli::parse();
let credentials = Credentials {
cube_url: args.cube,
username: args.username,
password: args.password,
token: args.token,
retries: args.retries,
ui: args.ui,
config_path: None,
};
match args.command {
Commands::Login {
no_keyring,
password_stdin,
} => {
let backend = if no_keyring {
Backend::ClearText
} else {
Backend::Keyring
};
login(credentials, backend, password_stdin).await
}
Commands::Switch {} => switch_login(credentials),
Commands::Whoami {} => whoami(credentials),
Commands::Logout {} => logout(credentials),
Commands::Ls(args) => ls(credentials, args).await,
Commands::Cd { plugin_instance } => cd(credentials, plugin_instance).await,
Commands::Status {
feed_or_plugin_instance,
execshell,
} => status(credentials, feed_or_plugin_instance, execshell).await,
Commands::Logs { plugin_instance } => logs(credentials, plugin_instance).await,
Commands::List(args) => list_feeds(credentials, args).await,
Commands::Search(args) => search_runnable(credentials, args).await,
Commands::Describe(args) => describe_runnable(credentials, args).await,
Commands::Run(args) => run_command(credentials, args).await,
Commands::Download(args) => download(credentials, args).await,
Commands::Upload(args) => upload(credentials, args).await,
}
}