1+ #![ forbid( unsafe_code) ]
2+
13use std:: collections:: { BTreeMap , BTreeSet } ;
24use std:: env;
35
46use anyhow:: Context ;
5- use clap:: { Arg , SubCommand } ;
7+ use clap:: Arg ;
68use derive_more:: Display ;
79use itertools:: Itertools ;
810use log:: { debug, error, info} ;
@@ -101,7 +103,7 @@ fn command_status(state: MigrationState) -> anyhow::Result<()> {
101103 }
102104 } )
103105 . collect :: < Vec < _ > > ( ) ;
104- let table = tabled:: Table :: new ( & data) . with ( tabled:: Style :: pseudo_clean ( ) ) ;
106+ let table = tabled:: Table :: new ( & data) . with ( tabled:: Style :: PSEUDO_CLEAN ) ;
105107 println ! ( "{}" , table) ;
106108 Ok ( ( ) )
107109}
@@ -144,7 +146,7 @@ fn command_upgrade(matches: &clap::ArgMatches, state: MigrationState) -> anyhow:
144146 } )
145147 . collect :: < Vec < _ > > ( ) ;
146148 let table = tabled:: Table :: new ( & plan_data)
147- . with ( tabled:: Style :: pseudo_clean ( ) )
149+ . with ( tabled:: Style :: PSEUDO_CLEAN )
148150 . with ( tabled:: Modify :: new ( tabled:: Column ( 2 ..=2 ) ) . with ( tabled:: Alignment :: left ( ) ) ) ;
149151 println ! ( "Migration plan:" ) ;
150152 println ! ( "{}" , table) ;
@@ -180,79 +182,78 @@ fn command_reset(matches: &clap::ArgMatches) -> anyhow::Result<()> {
180182}
181183
182184fn main ( ) -> anyhow:: Result < ( ) > {
183- let matches = clap:: App :: new ( env ! ( "CARGO_PKG_NAME" ) )
184- . version ( env ! ( "CARGO_PKG_VERSION" ) )
185- . author ( env ! ( "CARGO_PKG_AUTHORS" ) )
186- . about ( env ! ( "CARGO_PKG_DESCRIPTION" ) )
187- . global_settings ( & [ clap:: AppSettings :: ColorAuto , clap:: AppSettings :: ColoredHelp ] )
185+ let matches = clap:: App :: new ( clap:: crate_name!( ) )
186+ . version ( clap:: crate_version!( ) )
187+ . author ( clap:: crate_authors!( ) )
188+ . about ( clap:: crate_description!( ) )
188189 . arg (
189- Arg :: with_name ( "migration_path" )
190- . short ( "p" )
190+ Arg :: new ( "migration_path" )
191+ . short ( 'p' )
191192 . long ( "migration-path" )
192193 . takes_value ( true )
193194 . default_value ( "db" )
194195 . env ( "MIGRATION_PATH" )
195196 . help ( "Directory in which state is stored" ) ,
196197 )
197198 . arg (
198- Arg :: with_name ( "quiet" )
199- . short ( "q" )
199+ Arg :: new ( "quiet" )
200+ . short ( 'q' )
200201 . long ( "quiet" )
201202 . help ( "Be less noisy when logging" ) ,
202203 )
203204 . arg (
204- Arg :: with_name ( "verbose" )
205- . short ( "v" )
205+ Arg :: new ( "verbose" )
206+ . short ( 'v' )
206207 . long ( "verbose" )
207- . multiple ( true )
208+ . multiple_occurrences ( true )
208209 . help ( "Be more noisy when logging" ) ,
209210 )
210- . subcommand ( SubCommand :: with_name ( "status" ) . about ( "Show the current status of migrations" ) )
211+ . subcommand ( clap :: App :: new ( "status" ) . about ( "Show the current status of migrations" ) )
211212 . subcommand (
212- SubCommand :: with_name ( "generate" )
213+ clap :: App :: new ( "generate" )
213214 . about ( "Generate a new migration" )
214215 . arg (
215- Arg :: with_name ( "label" )
216+ Arg :: new ( "label" )
216217 . required ( true )
217218 . help ( "Descriptive one-line label for the migration" ) ,
218219 ) ,
219220 )
220221 . subcommand (
221- SubCommand :: with_name ( "upgrade" )
222+ clap :: App :: new ( "upgrade" )
222223 . about ( "Upgrade to the given revision" )
223224 . arg (
224- Arg :: with_name ( "revision" )
225+ Arg :: new ( "revision" )
225226 . required ( true )
226227 . help ( "Revision to which to upgrade (or 'latest')" ) ,
227228 )
228229 . arg (
229- Arg :: with_name ( "execute" )
230- . short ( "x" )
230+ Arg :: new ( "execute" )
231+ . short ( 'x' )
231232 . long ( "execute" )
232233 . help ( "Actually upgrade (otherwise will just print what will be done" ) ,
233234 ) ,
234235 )
235236 . subcommand (
236- SubCommand :: with_name ( "downgrade" )
237+ clap :: App :: new ( "downgrade" )
237238 . about ( "Downgrade to the given revision" )
238239 . arg (
239- Arg :: with_name ( "revision" )
240+ Arg :: new ( "revision" )
240241 . required ( true )
241242 . help ( "Revision to which to downgrade" ) ,
242243 )
243244 . arg (
244- Arg :: with_name ( "execute" )
245- . short ( "x" )
245+ Arg :: new ( "execute" )
246+ . short ( 'x' )
246247 . long ( "execute" )
247248 . help ( "Actually upgrade (otherwise will just print what will be done" ) ,
248249 ) ,
249250 )
250251 . subcommand (
251- SubCommand :: with_name ( "reset" )
252+ clap :: App :: new ( "reset" )
252253 . about ( "Drop all tables and totally reset the database (DANGEROUS)" )
253254 . arg (
254- Arg :: with_name ( "execute" )
255- . short ( "x" )
255+ Arg :: new ( "execute" )
256+ . short ( 'x' )
256257 . long ( "execute" )
257258 . help ( "Actually reset" ) ,
258259 ) ,
@@ -264,20 +265,20 @@ fn main() -> anyhow::Result<()> {
264265 let current_state = MigrationState :: load ( matches. value_of ( "migration_path" ) . unwrap ( ) ) ?;
265266
266267 match matches. subcommand ( ) {
267- ( "generate" , Some ( smatches) ) => {
268+ Some ( ( "generate" , smatches) ) => {
268269 current_state. generate ( smatches. value_of ( "label" ) . unwrap ( ) ) ?
269270 }
270- ( "status" , _) => {
271+ Some ( ( "status" , _) ) => {
271272 command_status ( current_state) ?;
272273 }
273- ( "upgrade" , Some ( smatches) ) => {
274+ Some ( ( "upgrade" , smatches) ) => {
274275 command_upgrade ( smatches, current_state) ?;
275276 }
276- ( "downgrade" , Some ( smatches) ) => {
277+ Some ( ( "downgrade" , smatches) ) => {
277278 command_upgrade ( smatches, current_state) ?;
278279 }
279- ( "reset" , Some ( smatches) ) => command_reset ( smatches) ?,
280- ( _ , _ ) => {
280+ Some ( ( "reset" , smatches) ) => command_reset ( smatches) ?,
281+ _ => {
281282 anyhow:: bail!( "Must pass a command!" ) ;
282283 }
283284 } ;
0 commit comments