@@ -28,7 +28,7 @@ func restoreCmd(passedExecs execs, cmdConfig *cmdConfiguration) (*cobra.Command,
2828 PreRun : func (cmd * cobra.Command , args []string ) {
2929 bindFlags (cmd , v )
3030 },
31- Args : cobra .MinimumNArgs ( 1 ),
31+ Args : cobra .RangeArgs ( 0 , 1 ),
3232 RunE : func (cmd * cobra.Command , args []string ) error {
3333 cmdConfig .logger .Debug ("starting restore" )
3434 ctx := context .Background ()
@@ -40,8 +40,20 @@ func restoreCmd(passedExecs execs, cmdConfig *cmdConfiguration) (*cobra.Command,
4040 }()
4141 ctx = util .ContextWithTracer (ctx , tracer )
4242 _ , startupSpan := tracer .Start (ctx , "startup" )
43- targetFile := args [0 ]
44- target := v .GetString ("target" )
43+
44+ // Get target from args[0], --target flag, or DB_RESTORE_TARGET environment variable
45+ var target string
46+ if len (args ) > 0 {
47+ target = args [0 ]
48+ } else {
49+ target = v .GetString ("target" )
50+ }
51+ if target == "" {
52+ return fmt .Errorf ("target must be specified as argument, --target flag, or DB_RESTORE_TARGET environment variable" )
53+ }
54+
55+ // Always pass empty targetFile to use the full path from the URL
56+ targetFile := ""
4557 // get databases namesand mappings
4658 databasesMap := make (map [string ]string )
4759 databases := strings .TrimSpace (v .GetString ("database" ))
@@ -144,9 +156,6 @@ func restoreCmd(passedExecs execs, cmdConfig *cmdConfiguration) (*cobra.Command,
144156
145157 flags := cmd .Flags ()
146158 flags .String ("target" , "" , "full URL target to the backup that you wish to restore" )
147- if err := cmd .MarkFlagRequired ("target" ); err != nil {
148- return nil , err
149- }
150159
151160 // compression
152161 flags .String ("compression" , defaultCompression , "Compression to use. Supported are: `gzip`, `bzip2`, `none`" )
0 commit comments