pax_global_header00006660000000000000000000000064142545240400014512gustar00rootroot0000000000000052 comment=06c8d8e974564e3556c86ba7e4e5ace7f61dbd21 mango-cobra-1.2.0/000077500000000000000000000000001425452404000136775ustar00rootroot00000000000000mango-cobra-1.2.0/.github/000077500000000000000000000000001425452404000152375ustar00rootroot00000000000000mango-cobra-1.2.0/.github/FUNDING.yml000066400000000000000000000000171425452404000170520ustar00rootroot00000000000000github: muesli mango-cobra-1.2.0/.github/dependabot.yml000066400000000000000000000004231425452404000200660ustar00rootroot00000000000000version: 2 updates: - package-ecosystem: "gomod" directory: "/" schedule: interval: "daily" labels: - "dependencies" - package-ecosystem: "github-actions" directory: "/" schedule: interval: "daily" labels: - "dependencies" mango-cobra-1.2.0/.github/workflows/000077500000000000000000000000001425452404000172745ustar00rootroot00000000000000mango-cobra-1.2.0/.github/workflows/build.yml000066400000000000000000000011171425452404000211160ustar00rootroot00000000000000name: build on: [push, pull_request] jobs: build: strategy: matrix: go-version: [~1.15, ^1] os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} env: GO111MODULE: "on" steps: - name: Install Go uses: actions/setup-go@v3 with: go-version: ${{ matrix.go-version }} - name: Checkout code uses: actions/checkout@v3 - name: Download Go modules run: go mod download - name: Build run: go build -v ./... - name: Test run: go test ./... mango-cobra-1.2.0/.github/workflows/coverage.yml000066400000000000000000000013211425452404000216070ustar00rootroot00000000000000name: coverage on: [push, pull_request] jobs: coverage: strategy: matrix: go-version: [^1] os: [ubuntu-latest] runs-on: ${{ matrix.os }} env: GO111MODULE: "on" steps: - name: Install Go uses: actions/setup-go@v3 with: go-version: ${{ matrix.go-version }} - name: Checkout code uses: actions/checkout@v3 - name: Coverage env: COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | go test -race -covermode atomic -coverprofile=profile.cov ./... GO111MODULE=off go get github.com/mattn/goveralls $(go env GOPATH)/bin/goveralls -coverprofile=profile.cov -service=github mango-cobra-1.2.0/.github/workflows/lint-soft.yml000066400000000000000000000011731425452404000217400ustar00rootroot00000000000000name: lint-soft on: push: pull_request: permissions: contents: read # Optional: allow read access to pull request. Use with `only-new-issues` option. pull-requests: read jobs: golangci: name: lint-soft runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: # Optional: golangci-lint command line arguments. args: --config .golangci-soft.yml --issues-exit-code=0 # Optional: show only new issues if it's a pull request. The default value is `false`. only-new-issues: true mango-cobra-1.2.0/.github/workflows/lint.yml000066400000000000000000000011011425452404000207560ustar00rootroot00000000000000name: lint on: push: pull_request: permissions: contents: read # Optional: allow read access to pull request. Use with `only-new-issues` option. pull-requests: read jobs: golangci: name: lint runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: # Optional: golangci-lint command line arguments. #args: # Optional: show only new issues if it's a pull request. The default value is `false`. only-new-issues: true mango-cobra-1.2.0/.gitignore000066400000000000000000000004361425452404000156720ustar00rootroot00000000000000# Binaries for programs and plugins *.exe *.exe~ *.dll *.so *.dylib # Test binary, built with `go test -c` *.test # Output of the go coverage tool, specifically when used with LiteIDE *.out # Dependency directories (remove the comment below to include it) # vendor/ example/example mango-cobra-1.2.0/.golangci-soft.yml000066400000000000000000000012701425452404000172340ustar00rootroot00000000000000run: tests: false issues: include: - EXC0001 - EXC0005 - EXC0011 - EXC0012 - EXC0013 max-issues-per-linter: 0 max-same-issues: 0 linters: enable: # - dupl - exhaustive # - exhaustivestruct - goconst - godot - godox - gomnd - gomoddirectives - goprintffuncname - ifshort # - lll - misspell - nakedret - nestif - noctx - nolintlint - prealloc - wrapcheck # disable default linters, they are already enabled in .golangci.yml disable: - deadcode - errcheck - gosimple - govet - ineffassign - staticcheck - structcheck - typecheck - unused - varcheck mango-cobra-1.2.0/.golangci.yml000066400000000000000000000006051425452404000162640ustar00rootroot00000000000000run: tests: false issues: include: - EXC0001 - EXC0005 - EXC0011 - EXC0012 - EXC0013 max-issues-per-linter: 0 max-same-issues: 0 linters: enable: - bodyclose - exportloopref - goimports - gosec - nilerr - predeclared - revive - rowserrcheck - sqlclosecheck - tparallel - unconvert - unparam - whitespace mango-cobra-1.2.0/LICENSE000066400000000000000000000020671425452404000147110ustar00rootroot00000000000000MIT License Copyright (c) 2022 Christian Muehlhaeuser Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. mango-cobra-1.2.0/README.md000066400000000000000000000021171425452404000151570ustar00rootroot00000000000000# mango-cobra [![Latest Release](https://img.shields.io/github/release/muesli/mango-cobra.svg)](https://github.com/muesli/mango-cobra/releases) [![Build Status](https://github.com/muesli/mango-cobra/workflows/build/badge.svg)](https://github.com/muesli/mango-cobra/actions) [![Go ReportCard](https://goreportcard.com/badge/muesli/mango-cobra)](https://goreportcard.com/report/muesli/mango-cobra) [![GoDoc](https://godoc.org/github.com/golang/gddo?status.svg)](https://pkg.go.dev/github.com/muesli/mango-cobra) cobra adapter for [mango](https://github.com/muesli/mango). ## Example ```go import ( "fmt" mcobra "github.com/muesli/mango-cobra" "github.com/muesli/roff" "github.com/spf13/cobra" ) var ( rootCmd = &cobra.Command{ Use: "mango", Short: "A man-page generator", } ) func main() { manPage, err := mcobra.NewManPage(1, rootCmd) if err != nil { panic(err) } manPage = manPage.WithSection("Copyright", "(C) 2022 Christian Muehlhaeuser.\n"+ "Released under MIT license.") fmt.Println(manPage.Build(roff.NewDocument())) } ``` mango-cobra-1.2.0/example/000077500000000000000000000000001425452404000153325ustar00rootroot00000000000000mango-cobra-1.2.0/example/main.go000066400000000000000000000027571425452404000166200ustar00rootroot00000000000000package main import ( "fmt" "os" mcobra "github.com/muesli/mango-cobra" "github.com/muesli/roff" "github.com/spf13/cobra" ) var ( rootCmd = &cobra.Command{ Use: "mango", Short: "A man-page generator", Long: "mango is a man-page generator for the Go flag, pflag, and cobra packages.\n" + "Features:\n" + "* User-friendly\n" + "* Plugable", RunE: func(cmd *cobra.Command, agrs []string) error { return nil }, } oneCmd = &cobra.Command{ Use: "1 [arg]", Example: "1 foobar", Short: "The first command", RunE: func(cmd *cobra.Command, agrs []string) error { return nil }, } twoCmd = &cobra.Command{ Use: "2", Short: "The second command", RunE: func(cmd *cobra.Command, agrs []string) error { return nil }, } config string one string two string ) func init() { rootCmd.PersistentFlags().StringVar(&config, "config", "", "config file (default is $HOME/.mango.yaml)") oneCmd.Flags().StringVar(&one, "one", "", "first value") oneCmd.Flags().StringVar(&two, "two", "", "second value") rootCmd.AddCommand(oneCmd) rootCmd.AddCommand(twoCmd) } func main() { manPage, err := mcobra.NewManPage(1, rootCmd) if err != nil { fmt.Println(err) os.Exit(1) } manPage = manPage.WithSection("Authors", "mango was written by Christian Muehlhaeuser "). WithSection("Copyright", "Copyright (C) 2022 Christian Muehlhaeuser.\n"+ "Released under MIT license.") fmt.Println(manPage.Build(roff.NewDocument())) } mango-cobra-1.2.0/go.mod000066400000000000000000000004601425452404000150050ustar00rootroot00000000000000module github.com/muesli/mango-cobra go 1.17 require ( github.com/muesli/mango v0.1.0 github.com/muesli/mango-pflag v0.1.0 github.com/muesli/roff v0.1.0 github.com/spf13/cobra v1.5.0 ) require ( github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/spf13/pflag v1.0.5 // indirect ) mango-cobra-1.2.0/go.sum000066400000000000000000000025711425452404000150370ustar00rootroot00000000000000github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/muesli/mango v0.1.0 h1:DZQK45d2gGbql1arsYA4vfg4d7I9Hfx5rX/GCmzsAvI= github.com/muesli/mango v0.1.0/go.mod h1:5XFpbC8jY5UUv89YQciiXNlbi+iJgt29VDC5xbzrLL4= github.com/muesli/mango-pflag v0.1.0 h1:UADqbYgpUyRoBja3g6LUL+3LErjpsOwaC9ywvBWe7Sg= github.com/muesli/mango-pflag v0.1.0/go.mod h1:YEQomTxaCUp8PrbhFh10UfbhbQrM/xJ4i2PB8VTLLW0= github.com/muesli/roff v0.1.0 h1:YD0lalCotmYuF5HhZliKWlIx7IEhiXeSfq7hNjFqGF8= github.com/muesli/roff v0.1.0/go.mod h1:pjAHQM9hdUUwm/krAfrLGgJkXJ+YuhtsfZ42kieB2Ig= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU= github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= mango-cobra-1.2.0/mcobra.go000066400000000000000000000025511425452404000154740ustar00rootroot00000000000000package mcobra import ( "github.com/muesli/mango" mpflag "github.com/muesli/mango-pflag" "github.com/spf13/cobra" ) // NewManPageFromCobra creates a new mango.ManPage from a cobra.Command. func NewManPage(section uint, c *cobra.Command) (*mango.ManPage, error) { manPage := mango.NewManPage(section, c.Name(), c.Short). WithLongDescription(c.Long) if err := AddCommand(manPage, c); err != nil { return nil, err } return manPage, nil } // AddCommand adds a cobra.Command to a mango.ManPage. func AddCommand(m *mango.ManPage, c *cobra.Command) error { return addCommandTree(m, c, nil) } func addCommandTree(m *mango.ManPage, c *cobra.Command, parent *mango.Command) error { var item *mango.Command if parent == nil { // set root command item = mango.NewCommand(c.Name(), "", "") m.Root = *item } else { item = mango.NewCommand(c.Name(), c.Short, c.Use) if err := parent.AddCommand(item); err != nil { return err } } // add commands if c.HasSubCommands() { for _, sub := range c.Commands() { if sub.Hidden { // ignore hidden commands continue } if err := addCommandTree(m, sub, item); err != nil { return err } } } // add flags if c.HasFlags() { c.Flags().VisitAll(mpflag.PFlagCommandVisitor(item)) } if c.HasPersistentFlags() { c.PersistentFlags().VisitAll(mpflag.PFlagCommandVisitor(item)) } return nil }