mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 19:13:34 +00:00
feat: uc docs --manual flag to generate manual pages (#302)
This adds 'doc --manual' that generates the manual pages in the current directory. This allows for packaging the manual pages in the same way as the completion, e.g. https://github.com/miekg/unpkg/blob/main/deb/uncloud/debian/rules#L28 (For debian packages local manpages should be included) Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
@@ -13,6 +13,10 @@ import (
|
|||||||
|
|
||||||
const docsDir = "website/docs/9-cli-reference"
|
const docsDir = "website/docs/9-cli-reference"
|
||||||
|
|
||||||
|
type docOptions struct {
|
||||||
|
manual bool
|
||||||
|
}
|
||||||
|
|
||||||
type cmdWrapper struct {
|
type cmdWrapper struct {
|
||||||
cmd *cobra.Command
|
cmd *cobra.Command
|
||||||
}
|
}
|
||||||
@@ -20,6 +24,7 @@ type cmdWrapper struct {
|
|||||||
// NewDocsCommand creates a new hidden command to generate CLI reference docs.
|
// NewDocsCommand creates a new hidden command to generate CLI reference docs.
|
||||||
func NewDocsCommand() *cobra.Command {
|
func NewDocsCommand() *cobra.Command {
|
||||||
wrapper := &cmdWrapper{}
|
wrapper := &cmdWrapper{}
|
||||||
|
opts := docOptions{}
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "docs",
|
Use: "docs",
|
||||||
Short: "Generate Uncloud CLI reference docs",
|
Short: "Generate Uncloud CLI reference docs",
|
||||||
@@ -29,6 +34,28 @@ func NewDocsCommand() *cobra.Command {
|
|||||||
Args: cobra.NoArgs,
|
Args: cobra.NoArgs,
|
||||||
ValidArgsFunction: cobra.NoFileCompletions,
|
ValidArgsFunction: cobra.NoFileCompletions,
|
||||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||||
|
if opts.manual {
|
||||||
|
header := &doc.GenManHeader{
|
||||||
|
Title: "Uncloud",
|
||||||
|
Section: "1",
|
||||||
|
Source: "Uncloud https://uncloud.run",
|
||||||
|
}
|
||||||
|
if err := doc.GenManTree(cmd.Root(), header, "."); err != nil {
|
||||||
|
return fmt.Errorf("generate CLI manual pages: %w", err)
|
||||||
|
}
|
||||||
|
completionFiles, err := filepath.Glob("uc-completion*.1")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("list generated manual pages: %w", err)
|
||||||
|
}
|
||||||
|
for _, f := range completionFiles {
|
||||||
|
if err = os.Remove(f); err != nil {
|
||||||
|
return fmt.Errorf("remove '%s': %w", f, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Remove existing markdown files.
|
// Remove existing markdown files.
|
||||||
mdFiles, err := filepath.Glob(filepath.Join(docsDir, "*.md"))
|
mdFiles, err := filepath.Glob(filepath.Join(docsDir, "*.md"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -72,6 +99,8 @@ func NewDocsCommand() *cobra.Command {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
cmd.Flags().BoolVar(&opts.manual, "manual", false,
|
||||||
|
"Generate Uncloud manual pages in the current directory.")
|
||||||
|
|
||||||
wrapper.cmd = cmd
|
wrapper.cmd = cmd
|
||||||
return cmd
|
return cmd
|
||||||
|
|||||||
Reference in New Issue
Block a user