Implement dataset deletion
This commit is contained in:
parent
0e9fddec9e
commit
c3a35c5ef6
2 changed files with 49 additions and 18 deletions
33
src/main.rs
33
src/main.rs
|
|
@ -17,10 +17,16 @@ use datasets::*;
|
|||
#[command(name = "StartGGElo")]
|
||||
#[command(author = "Kiana Sheibani <kiana.a.sheibani@gmail.com>")]
|
||||
#[command(version = "0.1.0")]
|
||||
#[command(about = "Elo rating calculator for start.gg tournaments", long_about = None)]
|
||||
#[command(about = "StartGGElo - Elo rating calculator for start.gg tournaments", long_about = None)]
|
||||
struct Cli {
|
||||
#[command(subcommand)]
|
||||
subcommand: Subcommands,
|
||||
|
||||
#[arg(short = 'A', long = "auth", value_name = "TOKEN", global = true)]
|
||||
auth_token: Option<String>,
|
||||
|
||||
#[arg(short, long = "config", value_name = "DIR", global = true)]
|
||||
config_dir: Option<PathBuf>,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
|
|
@ -35,6 +41,7 @@ enum Subcommands {
|
|||
enum DatasetSC {
|
||||
List,
|
||||
New { name: Option<String> },
|
||||
Delete { name: Option<String> },
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
@ -47,13 +54,16 @@ fn main() {
|
|||
Subcommands::Dataset {
|
||||
subcommand: DatasetSC::New { name },
|
||||
} => dataset_new(name),
|
||||
Subcommands::Dataset {
|
||||
subcommand: DatasetSC::Delete { name },
|
||||
} => dataset_delete(name),
|
||||
}
|
||||
}
|
||||
|
||||
fn dataset_list() {
|
||||
let config_dir = dirs::config_dir().unwrap();
|
||||
|
||||
let connection = open_datasets(&config_dir, None).unwrap();
|
||||
let connection = open_datasets(&config_dir).unwrap();
|
||||
let datasets = list_datasets(&connection).unwrap();
|
||||
|
||||
println!("{:?}", datasets);
|
||||
|
|
@ -72,6 +82,23 @@ fn dataset_new(name: Option<String>) {
|
|||
line.trim().to_owned()
|
||||
});
|
||||
|
||||
let connection = open_datasets(&config_dir, None).unwrap();
|
||||
let connection = open_datasets(&config_dir).unwrap();
|
||||
new_dataset(&connection, &name).unwrap();
|
||||
}
|
||||
|
||||
fn dataset_delete(name: Option<String>) {
|
||||
let config_dir = dirs::config_dir().unwrap();
|
||||
|
||||
let name = name.unwrap_or_else(|| {
|
||||
let mut line = String::new();
|
||||
print!("Dataset to delete: ");
|
||||
io::stdout().flush().expect("Could not access stdout");
|
||||
io::stdin()
|
||||
.read_line(&mut line)
|
||||
.expect("Could not read from stdin");
|
||||
line.trim().to_owned()
|
||||
});
|
||||
|
||||
let connection = open_datasets(&config_dir).unwrap();
|
||||
delete_dataset(&connection, &name).unwrap();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue