2020-07-16 12:12:48 +03:00
package commands
import (
2020-07-21 06:41:46 +03:00
"errors"
2020-07-16 12:12:48 +03:00
"github.com/spf13/cobra"
)
func newRmCommand ( ) * cobra . Command {
env := newEnv ( )
cmd := & cobra . Command {
2020-07-28 21:24:24 +03:00
Use : "rm ID" ,
2020-07-16 12:12:48 +03:00
Short : "Remove an existing bug." ,
2020-07-26 10:55:25 +03:00
Long : "Remove an existing bug in the local repository. Note removing bugs that were imported from bridges will not remove the bug on the remote, and will only remove the local copy of the bug." ,
2020-07-16 12:12:48 +03:00
PreRunE : loadBackendEnsureUser ( env ) ,
PostRunE : closeBackend ( env ) ,
RunE : func ( cmd * cobra . Command , args [ ] string ) error {
2020-07-20 04:55:14 +03:00
return runRm ( env , args )
2020-07-16 12:12:48 +03:00
} ,
}
flags := cmd . Flags ( )
flags . SortFlags = false
return cmd
}
2020-07-20 04:55:14 +03:00
func runRm ( env * Env , args [ ] string ) ( err error ) {
2020-07-24 06:25:38 +03:00
if len ( args ) == 0 {
return errors . New ( "you must provide a bug prefix to remove" )
2020-07-21 06:41:46 +03:00
}
2020-07-16 12:12:48 +03:00
2020-07-24 06:25:38 +03:00
err = env . backend . RemoveBug ( args [ 0 ] )
2020-07-16 12:12:48 +03:00
if err != nil {
2020-07-20 04:55:14 +03:00
return
2020-07-16 12:12:48 +03:00
}
env . out . Printf ( "bug %s removed\n" , args [ 0 ] )
2020-07-20 04:55:14 +03:00
return
2020-07-16 12:12:48 +03:00
}