help

package module
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: Apache-2.0 Imports: 7 Imported by: 24

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &bonzai.Cmd{
	Name:  `help`,
	Alias: `h|-h|--help|--h|/?`,
	Vers:  `v0.8.0`,
	Short: `display command help`,
	Long: `
		The {{code .Name}} command displays the help information for the
		immediate previous command unless it is passed arguments, in which
		case it resolves the arguments as if they were passed to the
		previous command and the help for the leaf command is displayed
		instead.`,

	Do: func(x *bonzai.Cmd, args ...string) (err error) {

		if len(args) > 0 {
			x, args, err = x.Caller().SeekInit(args...)
		} else {
			x = x.Caller()
		}

		md, err := mark.Bonzai(x)
		if err != nil {
			return err
		}

		styleMap := map[string]any{}
		if err := yaml.Unmarshal(Style, &styleMap); err != nil {
			return err
		}
		jsonBytes, err := json.Marshal(styleMap)
		if err != nil {
			return err
		}

		renderer, err := glamour.NewTermRenderer(
			glamour.WithAutoStyle(),
			glamour.WithPreservedNewLines(),
			glamour.WithStylesFromJSONBytes(jsonBytes),
		)

		if err != nil {
			return fmt.Errorf("developer-error: %v", err)
		}

		rendered, err := renderer.Render(md)
		if err != nil {
			return fmt.Errorf("developer-error: %v", err)
		}

		fmt.Println("\u001b[2J\u001b[H" + rendered)

		return nil
	},
}
View Source
var Style []byte

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
test
help-test command

Jump to

Keyboard shortcuts

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