Skip to content

Commit

Permalink
Allow to tag with multiple tags at once
Browse files Browse the repository at this point in the history
  • Loading branch information
timofurrer committed Oct 17, 2021
1 parent a9579ad commit 9eb5d59
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
12 changes: 6 additions & 6 deletions cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (
"github.com/spf13/viper"
)

var additionalTag string

var pushCmd = &cobra.Command{
Use: "push DOCS [PROJECT [VERSION]]",
Short: "Push documentation to a docat server",
Expand Down Expand Up @@ -106,20 +104,22 @@ Upload documentation to specific docat server:

log.Printf("Successfully pushed documentation version %s to project %s", version, project)

if additionalTag != "" {
err = docat.Tag(project, version, additionalTag)
tags, err := cmd.Flags().GetStringSlice("tag")
cobra.CheckErr(err)
for _, tag := range tags {
err = docat.Tag(project, version, tag)
if err != nil {
log.Fatal(err)
}

log.Printf("Successfully tagged version %s of project %s as %s", version, project, additionalTag)
log.Printf("Successfully tagged version %s of project %s as %s", version, project, tag)
}
},
}

func init() {
rootCmd.AddCommand(pushCmd)
pushCmd.PersistentFlags().StringVar(&additionalTag, "tag", "", "Additional Tag for this version")
pushCmd.PersistentFlags().StringSliceP("tag", "t", []string{}, "Additional Tag for this version (repeatable)")

setupEnv(pushCmd)
}
18 changes: 10 additions & 8 deletions cmd/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,29 @@ import (
)

var tagCmd = &cobra.Command{
Use: "tag PROJECT VERSION TAG",
Use: "tag PROJECT VERSION TAG..",
Short: "Tag an existing documentation on a docat server",
Long: `Tag an existing documentation on a docat server.
Tag documentation:
docatl tag --host https://localhost:8000 myproject 1.0.0 latest
`,
Args: cobra.ExactArgs(3),
Args: cobra.MinimumNArgs(3),
PreRun: func(cmd *cobra.Command, args []string) {
ensureHost()
},
Run: func(cmd *cobra.Command, args []string) {
project, version, tag := args[0], args[1], args[2]
project, version, tags := args[0], args[1], args[2:]

err := docat.Tag(project, version, tag)
if err != nil {
log.Fatal(err)
}
for _, tag := range tags {
err := docat.Tag(project, version, tag)
if err != nil {
log.Fatal(err)
}

log.Printf("Successfully tagged version %s of project %s as %s", version, project, tag)
log.Printf("Successfully tagged version %s of project %s as %s", version, project, tag)
}
},
}

Expand Down

0 comments on commit 9eb5d59

Please sign in to comment.