2021-02-02 00:53:33 +03:00
|
|
|
use std::path::PathBuf;
|
2021-02-23 18:16:26 +03:00
|
|
|
use structopt::clap;
|
2021-01-31 02:54:23 +03:00
|
|
|
pub use structopt::StructOpt;
|
|
|
|
|
|
|
|
#[derive(Debug, StructOpt)]
|
2021-02-02 00:53:33 +03:00
|
|
|
#[structopt(bin_name = "migra", name = "Migra")]
|
|
|
|
pub(crate) struct AppOpt {
|
|
|
|
#[structopt(short, long)]
|
|
|
|
pub config: Option<PathBuf>,
|
|
|
|
|
|
|
|
#[structopt(subcommand)]
|
|
|
|
pub command: Command,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, StructOpt)]
|
|
|
|
pub(crate) enum Command {
|
2021-01-31 02:54:23 +03:00
|
|
|
Init,
|
2021-02-02 00:53:33 +03:00
|
|
|
|
|
|
|
Apply(ApplyCommandOpt),
|
|
|
|
|
2021-02-03 01:03:56 +03:00
|
|
|
Make(MakeCommandOpt),
|
|
|
|
|
2021-02-02 00:53:33 +03:00
|
|
|
#[structopt(name = "list", visible_alias = "ls")]
|
|
|
|
List,
|
2021-02-02 00:55:41 +03:00
|
|
|
|
|
|
|
#[structopt(name = "upgrade", visible_alias = "up")]
|
2021-02-25 00:47:13 +03:00
|
|
|
Upgrade(UpgradeCommandOpt),
|
2021-02-02 00:55:41 +03:00
|
|
|
|
|
|
|
#[structopt(name = "downgrade", visible_alias = "down")]
|
2021-02-25 00:03:51 +03:00
|
|
|
Downgrade(DowngradeCommandOpt),
|
2021-02-23 18:16:26 +03:00
|
|
|
|
|
|
|
Completions(CompletionsShell),
|
2021-01-31 13:41:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, StructOpt)]
|
2021-02-02 00:53:33 +03:00
|
|
|
pub(crate) struct ApplyCommandOpt {
|
2021-01-31 13:41:12 +03:00
|
|
|
#[structopt(parse(from_str))]
|
2021-02-01 23:51:23 +03:00
|
|
|
pub file_name: String,
|
2021-01-31 02:54:23 +03:00
|
|
|
}
|
2021-02-03 01:03:56 +03:00
|
|
|
|
|
|
|
#[derive(Debug, StructOpt)]
|
|
|
|
pub(crate) struct MakeCommandOpt {
|
2021-02-25 00:47:13 +03:00
|
|
|
/// Name of the migration to create in specify directory.
|
2021-02-03 01:03:56 +03:00
|
|
|
#[structopt(parse(from_str))]
|
|
|
|
pub migration_name: String,
|
|
|
|
}
|
2021-02-23 18:16:26 +03:00
|
|
|
|
2021-02-25 00:47:13 +03:00
|
|
|
#[derive(Debug, StructOpt)]
|
|
|
|
pub(crate) struct UpgradeCommandOpt {
|
|
|
|
/// Name of the existing migration that will update the schema
|
|
|
|
/// in the database.
|
|
|
|
#[structopt(long = "name")]
|
|
|
|
pub migration_name: Option<String>,
|
2021-02-25 00:56:08 +03:00
|
|
|
|
|
|
|
/// How many existing migrations do we have to update.
|
|
|
|
#[structopt(long = "number", short = "n")]
|
|
|
|
pub migrations_number: Option<usize>,
|
2021-02-25 00:47:13 +03:00
|
|
|
}
|
|
|
|
|
2021-02-25 00:03:51 +03:00
|
|
|
#[derive(Debug, StructOpt)]
|
|
|
|
pub(crate) struct DowngradeCommandOpt {
|
2021-02-25 00:47:13 +03:00
|
|
|
/// How many applied migrations do we have to rollback.
|
2021-02-25 00:03:51 +03:00
|
|
|
#[structopt(long = "number", short = "n", default_value = "1")]
|
|
|
|
pub migrations_number: usize,
|
2021-02-25 00:20:40 +03:00
|
|
|
|
|
|
|
/// Rolls back all applied migrations. Ignores --number option.
|
|
|
|
#[structopt(long = "all")]
|
|
|
|
pub all_migrations: bool,
|
2021-02-25 00:03:51 +03:00
|
|
|
}
|
|
|
|
|
2021-02-23 18:16:26 +03:00
|
|
|
#[derive(Debug, StructOpt)]
|
|
|
|
pub(crate) enum CompletionsShell {
|
|
|
|
Bash,
|
|
|
|
Fish,
|
|
|
|
Zsh,
|
|
|
|
PowerShell,
|
|
|
|
Elvish,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<CompletionsShell> for clap::Shell {
|
|
|
|
fn from(shell: CompletionsShell) -> Self {
|
|
|
|
match shell {
|
|
|
|
CompletionsShell::Bash => Self::Bash,
|
|
|
|
CompletionsShell::Fish => Self::Fish,
|
|
|
|
CompletionsShell::Zsh => Self::Zsh,
|
|
|
|
CompletionsShell::PowerShell => Self::PowerShell,
|
|
|
|
CompletionsShell::Elvish => Self::Elvish,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|