Skip to content

Commit

Permalink
Add doc and shell completion generation commands
Browse files Browse the repository at this point in the history
Use 'doc' to generate manpages, and 'completion' to generate shell
completion scripts.

This changes <imgref> to IMGREF in the usage string because manpage
won't output <imgref>
  • Loading branch information
bcl committed Dec 20, 2023
1 parent b0a2d9e commit e6a2d74
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
36 changes: 31 additions & 5 deletions bib/cmd/bootc-image-builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/osbuild/images/pkg/rpmmd"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
)

//go:embed fedora-eln.json
Expand All @@ -26,6 +27,12 @@ const (
distroName = "fedora-39"
modulePlatformID = "platform:f39"
releaseVersion = "39"
helpTemplate = `{{.Short}}{{if .Long}}
Description:
{{.Long}}{{end}}
{{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}`
)

func fail(msg string) {
Expand Down Expand Up @@ -206,12 +213,13 @@ func build(cmd *cobra.Command, args []string) {

func main() {
rootCmd := &cobra.Command{
Use: "bootc-image-builder <imgref>",
Long: "create a bootable image from an ostree native container",
Args: cobra.ExactArgs(1),
DisableFlagsInUseLine: true,
Run: build,
Use: "bootc-image-builder [flags] IMGREF",
Short: "create bootable image",
Long: "create a bootable image from an ostree native container",
Args: cobra.ExactArgs(1),
Run: build,
}
rootCmd.SetHelpTemplate(helpTemplate)

logrus.SetLevel(logrus.ErrorLevel)
rootCmd.Flags().String("output", ".", "artifact output directory")
Expand All @@ -231,5 +239,23 @@ func main() {
check(rootCmd.MarkFlagFilename("config"))
rootCmd.MarkFlagsRequiredTogether("aws-region", "aws-bucket", "aws-ami-name")

// Add manpage generation command 'doc'
docCmd := &cobra.Command{
Use: "doc DIRECTORY",
Short: "Generate manpage files",
Long: "Generate manpage files for all the commands, one per file",
RunE: func(cmd *cobra.Command, args []string) error {
header := &doc.GenManHeader{
Title: "bootc-image-builder",
Section: "1",
Source: "bootc-image-builder",
}
return doc.GenManTree(rootCmd, header, args[0])
},
Args: cobra.ExactArgs(1),
}
docCmd.SetHelpTemplate(helpTemplate)
rootCmd.AddCommand(docCmd)

check(rootCmd.Execute())
}
2 changes: 2 additions & 0 deletions bib/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require (
github.com/containers/libtrust v0.0.0-20230121012942-c1716e8a8d01 // indirect
github.com/containers/ocicrypt v1.1.9 // indirect
github.com/containers/storage v1.51.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/cyberphone/json-canonicalization v0.0.0-20231011164504-785e29786b46 // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/distribution v2.8.3+incompatible // indirect
Expand Down Expand Up @@ -69,6 +70,7 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/proglottis/gpgme v0.1.3 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/secure-systems-lab/go-securesystemslib v0.7.0 // indirect
github.com/sigstore/fulcio v1.4.3 // indirect
github.com/sigstore/rekor v1.2.2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions bib/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ github.com/containers/ocicrypt v1.1.9 h1:2Csfba4jse85Raxk5HIyEk8OwZNjRvfkhEGijOj
github.com/containers/ocicrypt v1.1.9/go.mod h1:dTKx1918d8TDkxXvarscpNVY+lyPakPNFN4jwA9GBys=
github.com/containers/storage v1.51.0 h1:AowbcpiWXzAjHosKz7MKvPEqpyX+ryZA/ZurytRrFNA=
github.com/containers/storage v1.51.0/go.mod h1:ybl8a3j1PPtpyaEi/5A6TOFs+5TrEyObeKJzVtkUlfc=
github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0qnXZOBM=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cyberphone/json-canonicalization v0.0.0-20231011164504-785e29786b46 h1:2Dx4IHfC1yHWI12AxQDJM1QbRCDfk6M+blLzlZCXdrc=
Expand Down Expand Up @@ -236,6 +237,7 @@ github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/secure-systems-lab/go-securesystemslib v0.7.0 h1:OwvJ5jQf9LnIAS83waAjPbcMsODrTQUpJ02eNLUoxBg=
github.com/secure-systems-lab/go-securesystemslib v0.7.0/go.mod h1:/2gYnlnHVQ6xeGtfIqFy7Do03K4cdCY0A/GlJLDKLHI=
Expand Down

0 comments on commit e6a2d74

Please sign in to comment.