urfave_cli_docs

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2023 License: MIT Imports: 3 Imported by: 0

README

CLI docs generator

This package is deprecated. Use urfave/cli/v3 instead.

go_version tests coverage docs

For urfave-based applications.

$ go get gh.tarampamp.am/urfave-cli-docs@latest

Usage example

Add to your README.md file the following lines:

<!--GENERATED:CLI_DOCS-->
<!--/GENERATED:CLI_DOCS-->

Next, create a file generate_readme.go:

//go:build ignore
// +build ignore

package main

import (
	"os"

	"gh.tarampamp.am/urfave-cli-docs/markdown"

	"example"
)

func main() {
	var app = example.NewApp() // <-- your app here

	// generate markdown documentation for the app
	docs, err := markdown.Render(app)
	if err != nil {
		panic(err)
	}

	const readmeFilePath = "./readme.md"

	// read readme file
	readme, err := os.ReadFile(readmeFilePath)
	if err != nil {
		panic(err)
	}

	const start, end = "<!--GENERATED:CLI_DOCS-->", "<!--/GENERATED:CLI_DOCS-->"

	// replace the documentation section in the readme file
	updated, err := markdown.ReplaceBetween(start, end, string(readme), docs)
	if err != nil {
		panic(err)
	}

	// write the updated readme file
	if err = os.WriteFile(readmeFilePath, []byte(updated), 0664); err != nil {
		panic(err)
	}
}

Then, create a file generate.go for generating the documentation:

//go:build docs
// +build docs

package example

import _ "gh.tarampamp.am/urfave-cli-docs/markdown"

// Run using `go generate -tags docs ./...`

// Generate CLI usage documentation and write it to the README.md file (between special tags).
//go:generate go run generate_readme.go

And run code generation:

$ go generate -tags docs ./...

Viola! Now, open your readme file and watch the result. Example can be found here.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrepareMultilineString

func PrepareMultilineString(s string) string

PrepareMultilineString prepares a string (removes line breaks).

Types

type App deprecated

type App struct {
	AppPath                     string
	Name                        string
	Usage, UsageText, ArgsUsage string
	Description                 string
	GlobalFlags                 Flags
	Commands                    []Command
}

Deprecated: Use <https://github.com/urfave/cli/pull/1722> instead.

func NewApp deprecated

func NewApp(app *cli.App, appPath string) App

NewApp creates a new App struct.

Deprecated: Use <https://github.com/urfave/cli/pull/1722> instead.

type Command

type Command struct {
	AppPath                     string
	Name                        string
	Aliases                     []string
	Usage, UsageText, ArgsUsage string
	Description                 string
	Category                    string
	Flags                       Flags
	SubCommands                 []Command
	Level                       uint
}

func PrepareCommands

func PrepareCommands(commands []*cli.Command, appPath, parentCommandName string, level uint) []Command

PrepareCommands converts CLI commands into a structs for the rendering.

type Flag

type Flag struct {
	Name       string
	Aliases    []string
	Usage      string
	TakesValue bool
	Default    string
	EnvVars    []string
}

type Flags

type Flags []Flag

func PrepareFlags

func PrepareFlags(flags []cli.Flag) Flags

PrepareFlags converts CLI flags into a structs for the rendering.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL