on main help sign in
Switch CLI command names
696a6e5fabianlindfors
src/main.rs+51−6
@@ -21,10 +21,55 @@ struct Opts {
21#[derive(Parser)]
21#[derive(Parser)]
22#[clap(about)]
22#[clap(about)]
23enum Command {
23enum Command {
24+ #[clap(subcommand)]
25+ Migration(MigrationCommand),
26+
27+ #[clap(
28+ about = "Output the query your application should use to select the right schema",
29+ display_order = 2
30+ )]
31+ SchemaQuery(FindMigrationsOptions),
32+
33+ #[clap(
34+ about = "Deprecated. Use `reshape schema-query` instead",
35+ display_order = 3
36+ )]
37+ GenerateSchemaQuery(FindMigrationsOptions),
38+
39+ #[clap(
40+ about = "Deprecated. Use `reshape migration start` instead",
41+ display_order = 4
42+ )]
24 Migrate(MigrateOptions),
43 Migrate(MigrateOptions),
44+ #[clap(
45+ about = "Deprecated. Use `reshape migration complete` instead",
46+ display_order = 5
47+ )]
25 Complete(ConnectionOptions),
48 Complete(ConnectionOptions),
49+ #[clap(
50+ about = "Deprecated. Use `reshape migration abort` instead",
51+ display_order = 6
52+ )]
53+ Abort(ConnectionOptions),
54+}
55+
56+#[derive(Parser)]
57+#[clap(about = "Commands for managing migrations", display_order = 1)]
58+enum MigrationCommand {
59+ #[clap(
60+ about = "Starts a new migration, applying any migrations which haven't yet been applied",
61+ display_order = 1
62+ )]
63+ Start(MigrateOptions),
64+
65+ #[clap(about = "Completes an in-progress migration", display_order = 2)]
66+ Complete(ConnectionOptions),
67+
68+ #[clap(
69+ about = "Aborts an in-progress migration without losing any data",
70+ display_order = 3
71+ )]
26 Abort(ConnectionOptions),
72 Abort(ConnectionOptions),
27− GenerateSchemaQuery(FindMigrationsOptions),
28}
73}
29
74
30#[derive(Args)]
75#[derive(Args)]
@@ -67,7 +112,7 @@ fn main() -> anyhow::Result<()> {
67
112
68fn run(opts: Opts) -> anyhow::Result<()> {
113fn run(opts: Opts) -> anyhow::Result<()> {
69 match opts.cmd {
114 match opts.cmd {
70− Command::Migrate(opts) => {
115+ Command::Migration(MigrationCommand::Start(opts)) | Command::Migrate(opts) => {
71 let mut reshape = reshape_from_connection_options(&opts.connection_options)?;
116 let mut reshape = reshape_from_connection_options(&opts.connection_options)?;
72 let migrations = find_migrations(&opts.find_migrations_options)?;
117 let migrations = find_migrations(&opts.find_migrations_options)?;
73 reshape.migrate(migrations)?;
118 reshape.migrate(migrations)?;
@@ -79,16 +124,16 @@ fn run(opts: Opts) -> anyhow::Result<()> {
79
124
80 Ok(())
125 Ok(())
81 }
126 }
82− Command::Complete(opts) => {
127+ Command::Migration(MigrationCommand::Complete(opts)) | Command::Complete(opts) => {
83 let mut reshape = reshape_from_connection_options(&opts)?;
128 let mut reshape = reshape_from_connection_options(&opts)?;
84 reshape.complete()
129 reshape.complete()
85 }
130 }
86− Command::Abort(opts) => {
131+ Command::Migration(MigrationCommand::Abort(opts)) | Command::Abort(opts) => {
87 let mut reshape = reshape_from_connection_options(&opts)?;
132 let mut reshape = reshape_from_connection_options(&opts)?;
88 reshape.abort()
133 reshape.abort()
89 }
134 }
90− Command::GenerateSchemaQuery(find_migrations_options) => {
135+ Command::SchemaQuery(opts) | Command::GenerateSchemaQuery(opts) => {
91− let migrations = find_migrations(&find_migrations_options)?;
136+ let migrations = find_migrations(&opts)?;
92 let query = migrations
137 let query = migrations
93 .last()
138 .last()
94 .map(|migration| reshape::schema_query_for_migration(&migration.name));
139 .map(|migration| reshape::schema_query_for_migration(&migration.name));