example

package module
v0.0.0-...-483be4e Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

README

🌳 Go Bonzai™ Composite Command Tree

Create a new GitHub project using this template and change this README.md to match your project. Make all your template changes before making your first commit.

GoDoc License

Install

This command can be installed as a standalone program or composed into a Bonzai command tree.

Standalone

go install github.com/BuddhiLW/AutoPDF/cmd/bonzai-example@latest

Composed

package z

import (
	Z "github.com/rwxrob/bonzai/z"
	example "github.com/rwxrob/bonzai-example"
)

var Cmd = &Z.Cmd{
	Name:     `z`,
	Commands: []*Z.Cmd{help.Cmd, example.Cmd, example.BazCmd},
}

Tab Completion

To activate bash completion just use the complete -C option from your .bashrc or command line. There is no messy sourcing required. All the completion is done by the program itself.

complete -C bonzai-example bonzai-example

If you don't have bash or tab completion check use the shortcut commands instead.

Embedded Documentation

All documentation (like manual pages) has been embedded into the source code of the application. See the source or run the program with help to access it.

Reminders

  • Change bonzai-example every place to your project name (git grep bonzai-example)
  • Remove anything you don't need
  • Change .github/FUNDING.yaml to your own information
  • Update .gitignore to your liking
  • Will need to go get -u to update dependencies

Other Examples

Documentation

Overview

Package example provides the Bonzai command branch of the same name.

Copyright 2022 AutoPDF Pedro Branquinho SPDX-License-Identifier: Apache-2.0

Index

Constants

This section is empty.

Variables

View Source
var BarCmd = &Z.Cmd{
	Name: `bar`,

	Aliases: []string{"B", "notbar"},

	Commands: []*Z.Cmd{help.Cmd, fileCmd},

	Call: func(_ *Z.Cmd, _ ...string) error {
		log.Printf("would bar stuff")
		return nil
	},
}

exported branch

View Source
var BazCmd = &Z.Cmd{
	Name: `baz`,

	Aliases: []string{"Bz", "notbaz"},

	Commands: []*Z.Cmd{help.Cmd, fileCmd},

	Call: func(caller *Z.Cmd, none ...string) error {
		log.Print("Baz, suncreen song")
		return nil
	},
}

exported leaf

View Source
var CleanCmd = &Z.Cmd{
	Name: `clean`,
	Call: func(caller *Z.Cmd, none ...string) error {
		cmd := exec.Command("/bin/bash", "-c", "rm -rf pdfs/*.log pdfs/*.aux pdfs/*.synctex.gz pdfs/*.out pdfs/*.toc pdfs/*.fls pdfs/*.fdb_latexmk")
		err := cmd.Run()
		if err != nil {
			log.Fatal(err)
		}
		return nil
	},
}

exported leaf

View Source
var Cmd = &Z.Cmd{

	Name:      `example`,
	Summary:   `an example of Bonzai composite command tree, for generating PDFs using LaTeX`,
	Version:   `v0.1.1`,
	Copyright: `Copyright 2023 Pedro G. Branquinho`,
	License:   `Apache-2.0`,
	Site:      `buddhilw.com`,
	Source:    `git@github.com:BuddhiLW/AutoPDF.git`,
	Issues:    `github.com/BuddhiLW/AutoPDF/issues`,

	Commands: []*Z.Cmd{

		help.Cmd, conf.Cmd, vars.Cmd,

		BarCmd, ownCmd, pkgexampleCmd, CompileCmd, CleanCmd, BazCmd,
	},

	Dynamic: template.FuncMap{
		"uname": func(_ *Z.Cmd) string { return Z.Out("uname", "-a") },
		"dir":   func() string { return Z.Out("dir") },
	},

	Description: `
		The {{aka}} command is a well-documented example to get you started.
		You can start the description here and wrap it to look nice and it
		will just work.  Descriptions are written in BonzaiMark,
		a simplified combination of CommonMark, "go doc", and text/template
		that uses the Cmd itself as a data source and has a rich set of
		builtin template functions ({{pre "pre"}}, {{pre "exename"}},
		{{pre "indent"}}, etc.). There are four block types and four span types in
		BonzaiMark:

		Spans

		    Plain
		    *Italic*
		    **Bold**
		    ***BoldItalic***
		    <Under> (brackets remain)

		Note that on most terminals italic is rendered as underlining and
		depending on how old the terminal, other formatting might not appear
		as expected. If you know how to set LESS_TERMCAP_* variables they
		will be observed when output is to the terminal.

		Blocks

		1. Paragraph
		2. Verbatim (block begins with '    ', never first)
		3. Numbered (block begins with '* ')
		4. Bulleted (block begins with '1. ')

		Currently, a verbatim block must never be first because of the
		stripping of initial white space.

		Templates

		Anything from Cmd that fulfills the requirement to be included in
		a Go text/template may be used. This includes {{ "{{ cmd .Name }}" }}
		and the rest. A number of builtin template functions have also been
		added (such as {{ "indent" }}) which can receive piped input. You
		can add your own functions (or overwrite existing ones) by adding
		your own Dynamic template.FuncMap (see text/template for more about
		Go templates). Note that verbatim blocks will need to indented to work:

		    {{ "{{ dir | indent 4 }}" }}


		Produces a nice verbatim block:

		    {{ dir | indent 4 }}


		Note this is different for every user and their specific system. The
		ability to incorporate dynamic data into any help documentation is
		a game-changer not only for creating very consumable tools, but
		creating intelligent, interactive training and education materials
		as well.

		Templates Within Templates

		Sometimes you will need more text than can easily fit within
		a single action. (Actions may not span new lines.) For such things
		defining a template with that text is required and they you can
		include it with the {{pre "template" }} tag.

		    {{define "long" -}}
		    Here is something
		    that spans multiple
		    lines that would otherwise be too long for a single action.
		    {{- end}}

		Something
		`,

	Other: []Z.Section{
		{`Custom Sections`, `
			Additional sections can be added to the Other field.

			A Z.Section is just a Title and Body and can be assigned using
			composite notation (without the key names) for cleaner, in-code
			documentation.

			The Title will be capitalized for terminal output if using the
			common help.Cmd, but should use a suitable case for appearing in
			a book for other output renderers later (HTML, PDF, etc.)`,
		},
	},
}

Cmd provides a Bonzai branch command that can be composed into Bonzai trees or used as a standalone with light wrapper (see cmd/).

View Source
var CompileCmd = &Z.Cmd{
	Name: `compile`,
	Call: func(caller *Z.Cmd, none ...string) error {
		log.Print("Baz, suncreen song")
		cmd := exec.Command("/bin/bash", "-c", "pdflatex -synctex=1 -interaction=nonstopmode -output-directory=pdfs tex-models/main.tex")
		err := cmd.Run()
		if err != nil {
			log.Fatal(err)
		}
		return nil
	},
}

exported leaf

Functions

func Foo

func Foo(a string)

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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