diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 6cba7252..1b7251c9 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -23,6 +23,12 @@ jobs: with: python-version: '3.x' + - name: Set up Go 1.13 + uses: actions/setup-go@v1 + id: go + with: + go-version: 1.13 + - name: Install mkdocs env: MKDOCSMAT_TOKEN: ${{ secrets.MKDOCSMAT_TOKEN }} @@ -40,13 +46,11 @@ jobs: if: ${{ github.ref == 'refs/heads/main' }} run: | echo "DOCS_EDIT_URI=/edit/main/docs/" >> $GITHUB_ENV - echo "DOCS_VERSION=dev" >> $GITHUB_ENV - name: Update env for docs (latest) if: ${{ github.ref == 'refs/heads/latest' }} run: | echo "DOCS_EDIT_URI=/edit/latest/docs/" >> $GITHUB_ENV - echo "DOCS_VERSION=latest" >> $GITHUB_ENV - name: Setup Git env: @@ -58,4 +62,4 @@ jobs: - name: Deploy docs - run: mike deploy --push $DOCS_VERSION + run: mike deploy --push $(go run ./cli docs -V) diff --git a/cli/cmd/docs/docs.go b/cli/cmd/docs/docs.go index 5bfc195f..a4619732 100644 --- a/cli/cmd/docs/docs.go +++ b/cli/cmd/docs/docs.go @@ -2,6 +2,8 @@ package docs import ( "fmt" + "github.com/containrrr/shoutrrr/internal/meta" + "github.com/mattn/go-isatty" "os" "strings" @@ -21,6 +23,9 @@ var Cmd = &cobra.Command{ Short: "Print documentation for services", Run: Run, Args: func(cmd *cobra.Command, args []string) error { + if showVersion, _ := cmd.Flags().GetBool("version"); showVersion { + return nil + } serviceList := strings.Join(services, ", ") cmd.SetUsageTemplate(cmd.UsageTemplate() + "\nAvailable services: \n " + serviceList + "\n") return cobra.MinimumNArgs(1)(cmd, args) @@ -30,12 +35,22 @@ var Cmd = &cobra.Command{ func init() { Cmd.Flags().StringP("format", "f", "console", "Output format") + Cmd.Flags().BoolP("version", "V", false, "Show docs version") } // Run the docs command func Run(cmd *cobra.Command, args []string) { format, _ := cmd.Flags().GetString("format") + if showVersion, _ := cmd.Flags().GetBool("version"); showVersion { + _, _ = os.Stdout.WriteString(meta.DocsVersion) + if isatty.IsTerminal(os.Stdout.Fd()) { + // write a newline if the output is not being redirected + _, _ = os.Stdout.WriteString("\n") + } + os.Exit(cli.ExSuccess) + } + res := printDocs(format, args) if res.ExitCode != 0 { _, _ = fmt.Fprintf(os.Stderr, res.Message) diff --git a/go.mod b/go.mod index 71e60926..dc533a85 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/jarcoal/httpmock v1.0.4 github.com/klauspost/compress v1.11.7 // indirect github.com/mattn/go-colorable v0.1.8 + github.com/mattn/go-isatty v0.0.12 // indirect github.com/mitchellh/mapstructure v1.2.2 // indirect github.com/nxadm/tail v1.4.6 // indirect github.com/onsi/ginkgo v1.14.2