man

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package man enables man page generation of command line apps build with github.com/spf13/cobra.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate added in v1.4.18

func Generate(cmd *cobra.Command, options *Options, w io.Writer) error

Generate writes the man page, taking the given command as root, to a writer.

Example

ExampleGenerate generates a single man page describing all commands and sub-commands.

package main

import (
	"bytes"
	"fmt"
	"time"

	"github.com/coolduke/fritzctl/man"
	"github.com/spf13/cobra"
)

func main() {
	root := cobra.Command{
		Use: "myApp",
	}
	options := man.Options{
		Header: man.Header{
			Section: "1",
			Manual:  "myApp's man page",
			Title:   "myApp",
		},
		Origin: man.Origin{
			Date:   time.Date(2006, time.January, 1, 8, 0, 0, 0, time.UTC),
			Source: "written by a monkey on a typewriter",
		},
		SeeAlso: []string{"strace(1)"},
	}
	buf := new(bytes.Buffer)
	man.Generate(&root, &options, buf)
	s := buf.String()
	fmt.Println(s[0:26])
}
Output:

.nh
.TH myApp(1)Jan 2006
w

Types

type Header struct {
	// Man page title.
	Title string
	// Man page section.
	// Use "1" for General commands.
	// Use "2" for System calls.
	// Use "3" for Library functions, covering in particular the C standard library.
	// Use "4" for Special files (usually devices, those found in /dev) and drivers.
	// Use "5" for File formats and conventions.
	// Use "6" for Games and screensavers.
	// Use "7" for Miscellanea.
	// Use "8" for System administration commands and daemons.
	Section string
	// Manual title.
	Manual string
}

Header conveys general data of the man page.

type Options

type Options struct {
	Header  Header   // General data.
	Origin  Origin   // Data representing the origin of this man page.
	SeeAlso []string // Links to other man pages, e.g. "ps(1)"
}

Options specify the common properties of the man page.

type Origin

type Origin struct {
	Source string    // Origin of the man page.
	Date   time.Time // The Date when the man page was written.
}

Origin conveys data of the man page origin.

Jump to

Keyboard shortcuts

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