github.com/zaquestion/lab@v0.25.1/cmd/snippet_delete.go (about)

     1  package cmd
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/MakeNowJust/heredoc/v2"
     6  
     7  	"github.com/rsteube/carapace"
     8  	"github.com/spf13/cobra"
     9  	"github.com/zaquestion/lab/internal/action"
    10  	lab "github.com/zaquestion/lab/internal/gitlab"
    11  )
    12  
    13  // snippetDeleteCmd represents the snippetDelete command
    14  var snippetDeleteCmd = &cobra.Command{
    15  	Use:   "delete [remote] <id>",
    16  	Short: "Delete a project or personal snippet",
    17  	Example: heredoc.Doc(`
    18  		lab snippet delete origin 2147103
    19  		lab snippet delete -g 2147104`),
    20  	Args: cobra.MinimumNArgs(1),
    21  	Run: func(cmd *cobra.Command, args []string) {
    22  		rn, id, err := parseArgsRemoteAndID(args)
    23  		if err != nil {
    24  			log.Fatal(err)
    25  		}
    26  		if global || rn == "" {
    27  			err = lab.SnippetDelete(int(id))
    28  			if err != nil {
    29  				log.Fatal(err)
    30  			}
    31  			fmt.Printf("Snippet #%d deleted\n", id)
    32  			return
    33  		}
    34  
    35  		err = lab.ProjectSnippetDelete(rn, int(id))
    36  		if err != nil {
    37  			log.Fatal(err)
    38  		}
    39  	},
    40  }
    41  
    42  func init() {
    43  	snippetCmd.AddCommand(snippetDeleteCmd)
    44  	carapace.Gen(snippetDeleteCmd).PositionalCompletion(
    45  		action.Remotes(),
    46  		action.Snippets(snippetList),
    47  	)
    48  }