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