Skip to content

Commit d14f348

Browse files
committed
Clean up flags and fix empty required values
1 parent e535826 commit d14f348

3 files changed

Lines changed: 46 additions & 67 deletions

File tree

src/command.rs

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub enum Commands {
2020
id: Option<String>,
2121

2222
/// Workspace ID (defaults to first workspace from login)
23-
#[arg(long)]
23+
#[arg(long, global = true)]
2424
workspace_id: Option<String>,
2525

2626
/// Output format (used with dataset ID)
@@ -63,6 +63,10 @@ pub enum Commands {
6363

6464
/// Manage workspace connections
6565
Connections {
66+
/// Workspace ID (defaults to first workspace from login)
67+
#[arg(long, global = true)]
68+
workspace_id: Option<String>,
69+
6670
#[command(subcommand)]
6771
command: ConnectionsCommands,
6872
},
@@ -292,10 +296,6 @@ pub enum ConnectionsCreateCommands {
292296
/// Connection type name (e.g. postgres, mysql); omit to list all
293297
name: Option<String>,
294298

295-
/// Workspace ID (defaults to first workspace from login)
296-
#[arg(long)]
297-
workspace_id: Option<String>,
298-
299299
/// Output format
300300
#[arg(long, default_value = "table", value_parser = ["table", "json", "yaml"])]
301301
format: String,
@@ -305,29 +305,17 @@ pub enum ConnectionsCreateCommands {
305305
#[derive(Subcommand)]
306306
pub enum ConnectionsCommands {
307307
/// Interactively create a new connection
308-
New {
309-
/// Workspace ID (defaults to first workspace from login)
310-
#[arg(long)]
311-
workspace_id: Option<String>,
312-
},
308+
New,
313309

314310
/// List all connections for a workspace
315311
List {
316-
/// Workspace ID (defaults to first workspace from login)
317-
#[arg(long)]
318-
workspace_id: Option<String>,
319-
320312
/// Output format
321313
#[arg(long, default_value = "table", value_parser = ["table", "json", "yaml"])]
322314
format: String,
323315
},
324316

325317
/// Get details for a specific connection
326318
Get {
327-
/// Workspace ID (defaults to first workspace from login)
328-
#[arg(long)]
329-
workspace_id: Option<String>,
330-
331319
/// Connection ID
332320
connection_id: String,
333321

@@ -341,10 +329,6 @@ pub enum ConnectionsCommands {
341329
#[command(subcommand)]
342330
command: Option<ConnectionsCreateCommands>,
343331

344-
/// Workspace ID (defaults to first workspace from login)
345-
#[arg(long)]
346-
workspace_id: Option<String>,
347-
348332
/// Connection name
349333
#[arg(long)]
350334
name: Option<String>,
@@ -364,10 +348,6 @@ pub enum ConnectionsCommands {
364348

365349
/// Update a connection in a workspace
366350
Update {
367-
/// Workspace ID (defaults to first workspace from login)
368-
#[arg(long)]
369-
workspace_id: Option<String>,
370-
371351
/// Connection ID
372352
connection_id: String,
373353

@@ -390,10 +370,6 @@ pub enum ConnectionsCommands {
390370

391371
/// Delete a connection from a workspace
392372
Delete {
393-
/// Workspace ID (defaults to first workspace from login)
394-
#[arg(long)]
395-
workspace_id: Option<String>,
396-
397373
/// Connection ID
398374
connection_id: String,
399375
},

src/connections_new.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,14 @@ fn prompt_field(key: &str, field: &Value, is_required: bool) -> Option<Value> {
170170
("integer", _) => {
171171
let label = format!("{key}:");
172172
let t = Text::new(&label)
173-
.with_validator(|input: &str| {
174-
if input.is_empty() || input.parse::<i64>().is_ok() {
173+
.with_validator(move |input: &str| {
174+
if input.is_empty() {
175+
if is_required {
176+
return Ok(Validation::Invalid("This field is required".into()));
177+
}
178+
return Ok(Validation::Valid);
179+
}
180+
if input.parse::<i64>().is_ok() {
175181
Ok(Validation::Valid)
176182
} else {
177183
Ok(Validation::Invalid("Must be a whole number".into()))

src/main.rs

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -91,46 +91,43 @@ fn main() {
9191
WorkspaceCommands::List { format } => workspace::list(&format),
9292
_ => eprintln!("not yet implemented"),
9393
},
94-
Commands::Connections { command } => match command {
95-
ConnectionsCommands::New { workspace_id } => {
96-
let workspace_id = resolve_workspace(workspace_id);
97-
connections_new::run(&workspace_id)
98-
}
99-
ConnectionsCommands::Create { command, workspace_id, name, source_type, config, format } => {
100-
match command {
101-
Some(ConnectionsCreateCommands::List { name, workspace_id, format }) => {
102-
let workspace_id = resolve_workspace(workspace_id);
103-
match name.as_deref() {
104-
Some(name) => connections::types_get(&workspace_id, name, &format),
105-
None => connections::types_list(&workspace_id, &format),
94+
Commands::Connections { workspace_id, command } => {
95+
let workspace_id = resolve_workspace(workspace_id);
96+
match command {
97+
ConnectionsCommands::New => connections_new::run(&workspace_id),
98+
ConnectionsCommands::List { format } => {
99+
connections::list(&workspace_id, &format)
100+
}
101+
ConnectionsCommands::Create { command, name, source_type, config, format } => {
102+
match command {
103+
Some(ConnectionsCreateCommands::List { name, format }) => {
104+
match name.as_deref() {
105+
Some(name) => connections::types_get(&workspace_id, name, &format),
106+
None => connections::types_list(&workspace_id, &format),
107+
}
106108
}
107-
}
108-
None => {
109-
let missing: Vec<&str> = [
110-
name.is_none().then_some("--name"),
111-
source_type.is_none().then_some("--type"),
112-
config.is_none().then_some("--config"),
113-
].into_iter().flatten().collect();
114-
if !missing.is_empty() {
115-
eprintln!("error: missing required arguments: {}", missing.join(", "));
116-
std::process::exit(1);
109+
None => {
110+
let missing: Vec<&str> = [
111+
name.is_none().then_some("--name"),
112+
source_type.is_none().then_some("--type"),
113+
config.is_none().then_some("--config"),
114+
].into_iter().flatten().collect();
115+
if !missing.is_empty() {
116+
eprintln!("error: missing required arguments: {}", missing.join(", "));
117+
std::process::exit(1);
118+
}
119+
connections::create(
120+
&workspace_id,
121+
&name.unwrap(),
122+
&source_type.unwrap(),
123+
&config.unwrap(),
124+
&format,
125+
)
117126
}
118-
let workspace_id = resolve_workspace(workspace_id);
119-
connections::create(
120-
&workspace_id,
121-
&name.unwrap(),
122-
&source_type.unwrap(),
123-
&config.unwrap(),
124-
&format,
125-
)
126127
}
127128
}
128-
},
129-
ConnectionsCommands::List { workspace_id, format } => {
130-
let workspace_id = resolve_workspace(workspace_id);
131-
connections::list(&workspace_id, &format)
129+
_ => eprintln!("not yet implemented"),
132130
}
133-
_ => eprintln!("not yet implemented"),
134131
},
135132
Commands::Tables { command } => match command {
136133
TablesCommands::List { workspace_id, connection_id, schema, table, limit, cursor, format } => {

0 commit comments

Comments
 (0)