pcli

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 10, 2021 License: MIT Imports: 7 Imported by: 40

README

PCLI ✨

PCLI features drop-in functions to integrate PTerm into popular CLI frameworks for Go.

spf13/cobra

The drop-in functions must be used in your root.go file inside the init function.

Feature Replace With
Version Output rootCmd.SetVersionTemplate(pcli.GenerateVersionString(rootCmd.Name(), rootCmd.Version))
Help Function rootCmd.SetHelpFunc(pcli.Spf13CobraHelpFunc(rootCmd))
Error Function rootCmd.SetFlagErrorFunc(pcli.Spf13CobraFlagErrorFunc(rootCmd))

urfave/cli

The drop-in functions must be used in your main function, before app.Run(os.Args).

Feature Replace With
Version Output cli.VersionPrinter = pcli.UrfaveCliVersionPrinter
Help Function cli.HelpPrinterCustom = pcli.UrfaveCliHelpPrinterCustom(app)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HelpSectionPrinter = pterm.DefaultSection.WithLevel(2).Sprint

HelpSectionPrinter is used to print the different sections in the CLIs help output. You can overwrite it with any Sprint function.

Functions

func GenerateCopyrightString

func GenerateCopyrightString(copyright string) string

GenerateCopyrightString generates a pretty looking copyright string.

func GenerateTitleString

func GenerateTitleString(helpName string, version string) string

GenerateTitleString generates a pretty looking title string.

func GenerateVersionString

func GenerateVersionString(appName, version string) string

GenerateVersionString generates a pretty looking version string.

func Spf13CobraFlagErrorFunc

func Spf13CobraFlagErrorFunc(rootCmd *cobra.Command) func(*cobra.Command, error) error

Spf13CobraFlagErrorFunc is a drop in replacement for spf13/cobra `HelpFunc`

Usage:

rootCmd.SetFlagErrorFunc(pcli.Spf13CobraFlagErrorFunc(rootCmd))

func Spf13CobraHelpFunc

func Spf13CobraHelpFunc(rootCmd *cobra.Command) func(*cobra.Command, []string)

Spf13CobraHelpFunc is a drop in replacement for spf13/cobra `HelpFunc`

Usage:

rootCmd.SetHelpFunc(pcli.Spf13CobraHelpFunc(rootCmd))

func UrfaveCliHelpPrinterCustom

func UrfaveCliHelpPrinterCustom(app *cli.App) func(w io.Writer, templ string, data interface{}, customFunc map[string]interface{})

UrfaveCliHelpPrinterCustom is a drop in replacement for urfave/cli `HelpPrinterCustom` function.

Usage:

cli.HelpPrinterCustom = pcli.UrfaveCliHelpPrinterCustom(app)

func UrfaveCliVersionPrinter

func UrfaveCliVersionPrinter(c *cli.Context)

UrfaveCliVersionPrinter is a drop in replacement for urfave/cli `VersionPrinter` function.

Usage:

cli.VersionPrinter = pcli.UrfaveCliVersionPrinter

Types

This section is empty.

Jump to

Keyboard shortcuts

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