Skip to content

Commit

Permalink
add project delete command
Browse files Browse the repository at this point in the history
  • Loading branch information
kobtea committed Feb 26, 2017
1 parent 6ef9c9c commit 0d7275b
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions cmd/todoist/cmd/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,40 @@ var projectUpdateCmd = &cobra.Command{
},
}

var projectDeleteCmd = &cobra.Command{
Use: "delete id ...",
Short: "delete projects",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.New("Require project ID to delete")
}
var ids []todoist.ID
for _, i := range args {
id, err := todoist.NewID(i)
if err != nil {
return err
}
ids = append(ids, id)
}
client, err := newClient()
if err != nil {
return err
}
if err = client.Project.Delete(ids); err != nil {
return err
}
ctx := context.Background()
if err = client.Commit(ctx); err != nil {
return err
}
if err = client.FullSync(ctx, []todoist.Command{}); err != nil {
return err
}
fmt.Println("Successful deleting of project(s).")
return nil
},
}

func init() {
RootCmd.AddCommand(projectCmd)
projectCmd.AddCommand(projectListCmd)
Expand All @@ -149,4 +183,5 @@ func init() {
projectUpdateCmd.Flags().StringVarP(&projectColor, "color", "c", "", "color")
projectUpdateCmd.Flags().StringVarP(&projectIndent, "indent", "i", "", "indent")
projectCmd.AddCommand(projectUpdateCmd)
projectCmd.AddCommand(projectDeleteCmd)
}

0 comments on commit 0d7275b

Please sign in to comment.