@@ -194,15 +194,30 @@ func main() {
194194
195195 // The remaining arguments are going to be sent to the restic command line
196196 resticArguments := flags .resticArgs
197- resticCommand := global .DefaultCommand
198- if len (resticArguments ) > 0 {
199- resticCommand = resticArguments [0 ]
200- resticArguments = resticArguments [1 :]
201- }
197+ resticCommand := func () func (profile string ) string {
198+ if len (resticArguments ) > 0 {
199+ command := resticArguments [0 ]
200+ resticArguments = resticArguments [1 :]
201+ // Command specified in arguments list
202+ return func (profile string ) string {
203+ return command
204+ }
205+ } else {
206+ // Default command (as defined in global or profile)
207+ return func (profile string ) string {
208+ if c .HasProfile (profile ) {
209+ if p , err := c .GetProfile (profile ); err == nil && p .DefaultCommand != "" {
210+ return p .DefaultCommand
211+ }
212+ }
213+ return global .DefaultCommand
214+ }
215+ }
216+ }()
202217
203218 // resticprofile own commands (with configuration file)
204- if isOwnCommand (resticCommand , true ) {
205- err = runOwnCommand (c , resticCommand , flags , resticArguments )
219+ if isOwnCommand (resticCommand ( flags . name ) , true ) {
220+ err = runOwnCommand (c , resticCommand ( flags . name ) , flags , resticArguments )
206221 if err != nil {
207222 clog .Error (err )
208223 exitCode = 1
@@ -217,7 +232,7 @@ func main() {
217232 defer notifyStop ()
218233
219234 // Single profile run
220- err = runProfile (c , global , flags , flags .name , resticBinary , resticArguments , resticCommand , "" )
235+ err = runProfile (c , global , flags , flags .name , resticBinary , resticArguments , resticCommand ( flags . name ) , "" )
221236 if err != nil {
222237 clog .Error (err )
223238 exitCode = 1
@@ -237,7 +252,7 @@ func main() {
237252
238253 for i , profileName := range group {
239254 clog .Debugf ("[%d/%d] starting profile '%s' from group '%s'" , i + 1 , len (group ), profileName , flags .name )
240- err = runProfile (c , global , flags , profileName , resticBinary , resticArguments , resticCommand , flags .name )
255+ err = runProfile (c , global , flags , profileName , resticBinary , resticArguments , resticCommand ( profileName ) , flags .name )
241256 if err != nil {
242257 clog .Error (err )
243258 exitCode = 1
0 commit comments