@@ -28,7 +28,7 @@ func restoreCmd(passedExecs execs, cmdConfig *cmdConfiguration) (*cobra.Command,
28
28
PreRun : func (cmd * cobra.Command , args []string ) {
29
29
bindFlags (cmd , v )
30
30
},
31
- Args : cobra .MinimumNArgs ( 1 ),
31
+ Args : cobra .RangeArgs ( 0 , 1 ),
32
32
RunE : func (cmd * cobra.Command , args []string ) error {
33
33
cmdConfig .logger .Debug ("starting restore" )
34
34
ctx := context .Background ()
@@ -40,8 +40,20 @@ func restoreCmd(passedExecs execs, cmdConfig *cmdConfiguration) (*cobra.Command,
40
40
}()
41
41
ctx = util .ContextWithTracer (ctx , tracer )
42
42
_ , 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 := ""
45
57
// get databases namesand mappings
46
58
databasesMap := make (map [string ]string )
47
59
databases := strings .TrimSpace (v .GetString ("database" ))
@@ -144,9 +156,6 @@ func restoreCmd(passedExecs execs, cmdConfig *cmdConfiguration) (*cobra.Command,
144
156
145
157
flags := cmd .Flags ()
146
158
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
- }
150
159
151
160
// compression
152
161
flags .String ("compression" , defaultCompression , "Compression to use. Supported are: `gzip`, `bzip2`, `none`" )
0 commit comments