Skip to content

Commit

Permalink
ci: use docs tag from CLI constant
Browse files Browse the repository at this point in the history
  • Loading branch information
piksel committed Aug 16, 2021
1 parent eb79f79 commit 96315db
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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:
Expand All @@ -58,4 +62,4 @@ jobs:
- name: Deploy docs
run: mike deploy --push $DOCS_VERSION
run: mike deploy --push $(go run ./cli docs -V)
15 changes: 15 additions & 0 deletions cli/cmd/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package docs

import (
"fmt"
"github.com/containrrr/shoutrrr/internal/meta"
"github.com/mattn/go-isatty"
"os"
"strings"

Expand All @@ -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)
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 96315db

Please sign in to comment.