Giter VIP home page Giter VIP logo

cdocs's Introduction

cdocs - urfave/cli/v2 docs extension

License: MIT Go Report Card Coverage Status go.dev reference

This is an enhanced version of the ToMarkdown and ToMan methods for https://github.com/urfave/cli/v2.

cdocs also provides a helper command InstallManpageCommand that will generate a CLI command to install a man page to the system for the CLI tool.

Key differences are:

  • Addition of a Table of Contents with working markdown links.
  • UsageText included in generated doc files.
  • InstallManpageCommand helper command.

Examples:

Usage

package main

import (
	"fmt"
	"log"
	"os"
	"time"

	"github.com/clok/cdocs"
	"github.com/urfave/cli/v2"
)

func main() {
	im, err := cdocs.InstallManpageCommand(&cdocs.InstallManpageCommandInput{
		AppName: "demo",
	})
	if err != nil {
		log.Fatal(err)
	}

	app := &cli.App{
		Name:     "demo",
		Version:  "0.0.1",
		Compiled: time.Now(),
		Authors: []*cli.Author{
			{
				Name:  "John Doe",
				Email: "[email protected]",
			},
		},
		HelpName:             "demo",
		Usage:                "a demo cli app",
		EnableBashCompletion: true,
		Commands: []*cli.Command{
			{
				Name:  "s3",
				Usage: "simple S3 commands",
				Subcommands: []*cli.Command{
					{
						Name:      "get",
						Usage:     "[object path] [destination path]",
						UsageText: "it's going to get an object",
						Action: func(c *cli.Context) error {
							fmt.Println("get")
							return nil
						},
					},
				},
			},
			im,
			{
				Name:    "version",
				Aliases: []string{"v"},
				Usage:   "Print version info",
				Action: func(c *cli.Context) error {
					fmt.Println("version")
					return nil
				},
			},
		},
	}

	if os.Getenv("DOCS_MD") != "" {
		docs, err := cdocs.ToMarkdown(app)
		if err != nil {
			panic(err)
		}
		fmt.Println(docs)
		return
	}

	if os.Getenv("DOCS_MAN") != "" {
		docs, err := cdocs.ToMan(app)
		if err != nil {
			panic(err)
		}
		fmt.Println(docs)
		return
	}

	err = app.Run(os.Args)
	if err != nil {
		log.Fatal(err)
	}
}

Development

  1. Fork the clok/cdocs repo
  2. Use go >= 1.16
  3. Branch & Code
  4. Run linters ๐Ÿงน golangci-lint run
  5. Commit with a Conventional Commit
  6. Open a PR

cdocs's People

Contributors

clok avatar renovate[bot] avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

cdocs's Issues

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/lint.yml
  • actions/checkout v4
  • golangci/golangci-lint-action v3
  • ubuntu 22.04
.github/workflows/release.yml
  • actions/checkout v4
  • actions/setup-go v5
  • goreleaser/goreleaser-action v5
  • ubuntu 22.04
.github/workflows/test.yml
  • actions/setup-go v5
  • actions/checkout v4
  • jandelgado/gcov2lcov-action v1.0.9
  • coverallsapp/github-action v2.2.3
  • ubuntu 22.04
.github/workflows/warm.yaml
  • ubuntu 22.04
gomod
go.mod
  • go 1.18
  • github.com/clok/kemba v1.2.1
  • github.com/cpuguy83/go-md2man/v2 v2.0.3
  • github.com/stretchr/testify v1.8.4
  • github.com/urfave/cli/v2 v2.27.1

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.