diff --git a/.github/workflows/hugo.yaml b/.github/workflows/hugo.yaml index f49650a..9e16fed 100644 --- a/.github/workflows/hugo.yaml +++ b/.github/workflows/hugo.yaml @@ -1,10 +1,13 @@ -# Sample workflow for building and deploying a Hugo site to GitHub Pages +# Sample workflow for building and deploying a Hugo site to Pages name: Deploy Hugo site to Pages on: # Runs on pushes targeting the default branch push: branches: ["main"] + paths: + - 'docs/**' # Only trigger on changes to docs directory + - '.github/workflows/hugo.yml' # And on workflow file changes # Allows you to run this workflow manually from the Actions tab workflow_dispatch: @@ -16,7 +19,6 @@ permissions: id-token: write # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. -# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. concurrency: group: "pages" cancel-in-progress: false @@ -33,21 +35,42 @@ jobs: env: HUGO_VERSION: 0.128.0 steps: + # Add cache for Hugo modules and builds + - name: Cache Hugo resources + uses: actions/cache@v3 + with: + path: | + ${{ runner.temp }}/hugo_cache + ./docs/resources + key: ${{ runner.os }}-hugomod-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-hugomod- + - name: Install Hugo CLI run: | wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \ && sudo dpkg -i ${{ runner.temp }}/hugo.deb + - name: Install Dart Sass run: sudo snap install dart-sass + - name: Checkout uses: actions/checkout@v4 with: submodules: recursive + fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod + - name: Setup Pages id: pages uses: actions/configure-pages@v5 + - name: Install Node.js dependencies run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true" + + # Add HTML validation + - name: Setup HTML validation + run: npm install -g html-validator-cli + - name: Build with Hugo env: HUGO_CACHEDIR: ${{ runner.temp }}/hugo_cache @@ -57,6 +80,23 @@ jobs: --minify \ --source docs \ --baseURL "${{ steps.pages.outputs.base_url }}/" + + # Add error checking + - name: Check for Hugo errors + run: | + if [ -d "./docs/public" ]; then + echo "Build succeeded" + else + echo "Build failed" + exit 1 + fi + + # Validate HTML output + - name: Validate HTML + run: | + find ./docs/public -name '*.html' -exec html-validator {} \; + continue-on-error: true # Optional: set to false if you want validation errors to fail the build + - name: Upload artifact uses: actions/upload-pages-artifact@v3 with: @@ -73,3 +113,9 @@ jobs: - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v4 + + # Add deployment verification + - name: Verify deployment + run: | + curl -s --head --request GET ${{ steps.deployment.outputs.page_url }} | grep "200\|301" + shell: bash \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7553571..279e150 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,18 @@ go.work.sum # env file .env bin/ + +# Generated files by hugo +docs/themes/ +docs/public/ +/resources/_gen/ +/assets/jsconfig.json +hugo_stats.json + +# Executable may be added to repository +hugo.exe +hugo.darwin +hugo.linux + +# Temporary lock file while building +/.hugo_build.lock \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..47029a0 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "docs/themes/hugo-book"] + path = docs/themes/hugo-book + url = https://github.com/alex-shpak/hugo-book diff --git a/docs/config.toml b/docs/config.toml index 81eb872..ce87122 100644 --- a/docs/config.toml +++ b/docs/config.toml @@ -1,11 +1,37 @@ -baseURL = 'https://grimoire.cc/' +baseURL = 'https://gphorvath.github.io/grimoire/' languageCode = 'en-us' -title = 'Grimoire - AI Prompt Management CLI' +title = 'Grimoire - Prompt Engineering Assistant' +theme = 'hugo-book' +# Show all pages in left sidebar [params] - description = "A prompt engineer's Grimoire to assist with getting the best results from Generative AI prompts" + # Book theme parameters + BookTheme = 'dark' + BookToC = true + # Remove or comment out BookSection to show all content + # BookSection = 'docs' + BookRepo = 'https://github.com/gphorvath/grimoire' + BookEditPath = 'edit/main/docs' + + # Show all files in the menu + BookMenuBundle = '/menu' + # Set to true to show all hidden pages + BookShowHidden = true -[markup] - [markup.goldmark] - [markup.goldmark.renderer] - unsafe = true \ No newline at end of file +# Configure the menu +[menu] + # This will show all pages in the sidebar + [[menu.before]] + name = "GitHub" + url = "https://github.com/gphorvath/grimoire" + weight = 10 + +# Enable all files to be included in menu +[markup.tableOfContents] + startLevel = 1 + endLevel = 4 + +# Configure content browsing +[taxonomies] + category = "categories" + tag = "tags" diff --git a/docs/content/_index.md b/docs/content/_index.md new file mode 100644 index 0000000..2c1233d --- /dev/null +++ b/docs/content/_index.md @@ -0,0 +1,23 @@ +--- +title: "Command Reference" +description: "Complete reference for Grimoire CLI commands" +weight: 1 +date: 2024-11-09 +draft: false +--- + +# Command Reference + +This section contains the complete reference for all Grimoire CLI commands. + +## Available Commands + +* [completion](grimoire/completion/) - Generate the autocompletion script for the specified shell +* [copy](grimoire/copy/) - Copy the prompt to the clipboard +* [delete](grimoire/delete/) - Delete the prompt +* [docs](grimoire/docs/) - Generate documentation for grimoire +* [edit](grimoire/edit/) - Edit the prompt in the chosen editor +* [generate](grimoire/generate/) - Get generation from Ollama +* [help](grimoire/help/) - Help about any command +* [list](grimoire/list/) - List files in the target directory +* [say](grimoire/say/) - Print Grimoire logo diff --git a/docs/content/grimoire.md b/docs/content/grimoire/_index.md similarity index 56% rename from docs/content/grimoire.md rename to docs/content/grimoire/_index.md index ecc2910..126bae7 100644 --- a/docs/content/grimoire.md +++ b/docs/content/grimoire/_index.md @@ -1,8 +1,12 @@ -## grimoire +--- +title: "grimoire" +description: "Grimoire - A CLI tool for managing and using GenAI prompts" +weight: 1 +date: 2024-11-09 +draft: false +--- -Grimoire - A CLI tool for managing and using GenAI prompts - -### Synopsis +# grimoire ┌─────────────────────────────┐ @@ -22,20 +26,21 @@ Grimoire - A CLI tool for managing and using GenAI prompts Grimoire is your magical companion to manage and quickly access a collection of GenAI prompts. -### Options +## Usage -``` - -h, --help help for grimoire +```bash +grimoire ``` -### SEE ALSO +## Subcommands -* [grimoire completion](grimoire_completion.md) - Generate the autocompletion script for the specified shell -* [grimoire copy](grimoire_copy.md) - Copy the prompt to the clipboard -* [grimoire delete](grimoire_delete.md) - Delete the prompt -* [grimoire edit](grimoire_edit.md) - Edit the prompt in the chosen editor -* [grimoire generate](grimoire_generate.md) - Get generation from Ollama -* [grimoire list](grimoire_list.md) - List files in the target directory -* [grimoire say](grimoire_say.md) - Print Grimoire logo +* [completion](./completion/) - Generate the autocompletion script for the specified shell +* [copy](./copy/) - Copy the prompt to the clipboard +* [delete](./delete/) - Delete the prompt +* [docs](./docs/) - Generate documentation for grimoire +* [edit](./edit/) - Edit the prompt in the chosen editor +* [generate](./generate/) - Get generation from Ollama +* [help](./help/) - Help about any command +* [list](./list/) - List files in the target directory +* [say](./say/) - Print Grimoire logo -###### Auto generated by spf13/cobra on 9-Nov-2024 diff --git a/docs/content/grimoire/completion/_index.md b/docs/content/grimoire/completion/_index.md new file mode 100644 index 0000000..8caeab1 --- /dev/null +++ b/docs/content/grimoire/completion/_index.md @@ -0,0 +1,27 @@ +--- +title: "completion" +description: "Generate the autocompletion script for the specified shell" +weight: 2 +date: 2024-11-09 +draft: false +--- + +# grimoire completion + +Generate the autocompletion script for grimoire for the specified shell. +See each sub-command's help for details on how to use the generated script. + + +## Usage + +```bash +grimoire completion +``` + +## Subcommands + +* [bash](./bash/) - Generate the autocompletion script for bash +* [fish](./fish/) - Generate the autocompletion script for fish +* [powershell](./powershell/) - Generate the autocompletion script for powershell +* [zsh](./zsh/) - Generate the autocompletion script for zsh + diff --git a/docs/content/grimoire_completion_bash.md b/docs/content/grimoire/completion/bash/_index.md similarity index 61% rename from docs/content/grimoire_completion_bash.md rename to docs/content/grimoire/completion/bash/_index.md index b1aba24..111d8e7 100644 --- a/docs/content/grimoire_completion_bash.md +++ b/docs/content/grimoire/completion/bash/_index.md @@ -1,8 +1,12 @@ -## grimoire completion bash +--- +title: "bash" +description: "Generate the autocompletion script for bash" +weight: 3 +date: 2024-11-09 +draft: false +--- -Generate the autocompletion script for bash - -### Synopsis +# grimoire completion bash Generate the autocompletion script for the bash shell. @@ -26,19 +30,15 @@ To load completions for every new session, execute once: You will need to start a new shell for this setup to take effect. -``` -grimoire completion bash -``` +## Usage -### Options - -``` - -h, --help help for bash - --no-descriptions disable completion descriptions +```bash +grimoire completion bash ``` -### SEE ALSO +## Flags -* [grimoire completion](grimoire_completion.md) - Generate the autocompletion script for the specified shell +| Flag | Description | Default | +|------|-------------|----------| +| `--no-descriptions` | disable completion descriptions | `false` | -###### Auto generated by spf13/cobra on 9-Nov-2024 diff --git a/docs/content/grimoire_completion_fish.md b/docs/content/grimoire/completion/fish/_index.md similarity index 50% rename from docs/content/grimoire_completion_fish.md rename to docs/content/grimoire/completion/fish/_index.md index 8484552..40a4c82 100644 --- a/docs/content/grimoire_completion_fish.md +++ b/docs/content/grimoire/completion/fish/_index.md @@ -1,8 +1,12 @@ -## grimoire completion fish +--- +title: "fish" +description: "Generate the autocompletion script for fish" +weight: 4 +date: 2024-11-09 +draft: false +--- -Generate the autocompletion script for fish - -### Synopsis +# grimoire completion fish Generate the autocompletion script for the fish shell. @@ -17,19 +21,15 @@ To load completions for every new session, execute once: You will need to start a new shell for this setup to take effect. -``` -grimoire completion fish [flags] -``` +## Usage -### Options - -``` - -h, --help help for fish - --no-descriptions disable completion descriptions +```bash +grimoire completion fish [flags] ``` -### SEE ALSO +## Flags -* [grimoire completion](grimoire_completion.md) - Generate the autocompletion script for the specified shell +| Flag | Description | Default | +|------|-------------|----------| +| `--no-descriptions` | disable completion descriptions | `false` | -###### Auto generated by spf13/cobra on 9-Nov-2024 diff --git a/docs/content/grimoire/completion/powershell/_index.md b/docs/content/grimoire/completion/powershell/_index.md new file mode 100644 index 0000000..41645ea --- /dev/null +++ b/docs/content/grimoire/completion/powershell/_index.md @@ -0,0 +1,32 @@ +--- +title: "powershell" +description: "Generate the autocompletion script for powershell" +weight: 5 +date: 2024-11-09 +draft: false +--- + +# grimoire completion powershell + +Generate the autocompletion script for powershell. + +To load completions in your current shell session: + + grimoire completion powershell | Out-String | Invoke-Expression + +To load completions for every new session, add the output of the above command +to your powershell profile. + + +## Usage + +```bash +grimoire completion powershell [flags] +``` + +## Flags + +| Flag | Description | Default | +|------|-------------|----------| +| `--no-descriptions` | disable completion descriptions | `false` | + diff --git a/docs/content/grimoire_completion_zsh.md b/docs/content/grimoire/completion/zsh/_index.md similarity index 63% rename from docs/content/grimoire_completion_zsh.md rename to docs/content/grimoire/completion/zsh/_index.md index 25afef8..dcfcb38 100644 --- a/docs/content/grimoire_completion_zsh.md +++ b/docs/content/grimoire/completion/zsh/_index.md @@ -1,8 +1,12 @@ -## grimoire completion zsh +--- +title: "zsh" +description: "Generate the autocompletion script for zsh" +weight: 6 +date: 2024-11-09 +draft: false +--- -Generate the autocompletion script for zsh - -### Synopsis +# grimoire completion zsh Generate the autocompletion script for the zsh shell. @@ -28,19 +32,15 @@ To load completions for every new session, execute once: You will need to start a new shell for this setup to take effect. -``` -grimoire completion zsh [flags] -``` +## Usage -### Options - -``` - -h, --help help for zsh - --no-descriptions disable completion descriptions +```bash +grimoire completion zsh [flags] ``` -### SEE ALSO +## Flags -* [grimoire completion](grimoire_completion.md) - Generate the autocompletion script for the specified shell +| Flag | Description | Default | +|------|-------------|----------| +| `--no-descriptions` | disable completion descriptions | `false` | -###### Auto generated by spf13/cobra on 9-Nov-2024 diff --git a/docs/content/grimoire/copy/_index.md b/docs/content/grimoire/copy/_index.md new file mode 100644 index 0000000..6fb779d --- /dev/null +++ b/docs/content/grimoire/copy/_index.md @@ -0,0 +1,18 @@ +--- +title: "copy" +description: "Copy the prompt to the clipboard" +weight: 3 +date: 2024-11-09 +draft: false +--- + +# grimoire copy + +Copy the prompt to the clipboard + +## Usage + +```bash +grimoire copy [prompt name] +``` + diff --git a/docs/content/grimoire/delete/_index.md b/docs/content/grimoire/delete/_index.md new file mode 100644 index 0000000..ee5a058 --- /dev/null +++ b/docs/content/grimoire/delete/_index.md @@ -0,0 +1,18 @@ +--- +title: "delete" +description: "Delete the prompt" +weight: 4 +date: 2024-11-09 +draft: false +--- + +# grimoire delete + +Delete the prompt + +## Usage + +```bash +grimoire delete [prompt name] +``` + diff --git a/docs/content/grimoire/docs/_index.md b/docs/content/grimoire/docs/_index.md new file mode 100644 index 0000000..76eca29 --- /dev/null +++ b/docs/content/grimoire/docs/_index.md @@ -0,0 +1,24 @@ +--- +title: "docs" +description: "Generate documentation for grimoire" +weight: 5 +date: 2024-11-09 +draft: false +--- + +# grimoire docs + +Generate documentation for grimoire + +## Usage + +```bash +grimoire docs [flags] +``` + +## Flags + +| Flag | Description | Default | +|------|-------------|----------| +| `--help` | help for docs | `false` | + diff --git a/docs/content/grimoire/edit/_index.md b/docs/content/grimoire/edit/_index.md new file mode 100644 index 0000000..333e4fb --- /dev/null +++ b/docs/content/grimoire/edit/_index.md @@ -0,0 +1,18 @@ +--- +title: "edit" +description: "Edit the prompt in the chosen editor" +weight: 6 +date: 2024-11-09 +draft: false +--- + +# grimoire edit + +Edit the prompt in the chosen editor + +## Usage + +```bash +grimoire edit [prompt name] +``` + diff --git a/docs/content/grimoire/generate/_index.md b/docs/content/grimoire/generate/_index.md new file mode 100644 index 0000000..bfdcaae --- /dev/null +++ b/docs/content/grimoire/generate/_index.md @@ -0,0 +1,18 @@ +--- +title: "generate" +description: "Get generation from Ollama" +weight: 7 +date: 2024-11-09 +draft: false +--- + +# grimoire generate + +Get generation from Ollama + +## Usage + +```bash +grimoire generate [prompt] +``` + diff --git a/docs/content/grimoire/help/_index.md b/docs/content/grimoire/help/_index.md new file mode 100644 index 0000000..24e0da4 --- /dev/null +++ b/docs/content/grimoire/help/_index.md @@ -0,0 +1,19 @@ +--- +title: "help" +description: "Help about any command" +weight: 8 +date: 2024-11-09 +draft: false +--- + +# grimoire help + +Help provides help for any command in the application. +Simply type grimoire help [path to command] for full details. + +## Usage + +```bash +grimoire help [command] +``` + diff --git a/docs/content/grimoire/list/_index.md b/docs/content/grimoire/list/_index.md new file mode 100644 index 0000000..a8ef9ff --- /dev/null +++ b/docs/content/grimoire/list/_index.md @@ -0,0 +1,18 @@ +--- +title: "list" +description: "List files in the target directory" +weight: 9 +date: 2024-11-09 +draft: false +--- + +# grimoire list + +List files in the target directory + +## Usage + +```bash +grimoire list [directory] +``` + diff --git a/docs/content/grimoire/say/_index.md b/docs/content/grimoire/say/_index.md new file mode 100644 index 0000000..a4884f7 --- /dev/null +++ b/docs/content/grimoire/say/_index.md @@ -0,0 +1,18 @@ +--- +title: "say" +description: "Print Grimoire logo" +weight: 10 +date: 2024-11-09 +draft: false +--- + +# grimoire say + +Print out the Grimoire logo. + +## Usage + +```bash +grimoire say +``` + diff --git a/docs/content/grimoire_completion.md b/docs/content/grimoire_completion.md deleted file mode 100644 index d2decae..0000000 --- a/docs/content/grimoire_completion.md +++ /dev/null @@ -1,25 +0,0 @@ -## grimoire completion - -Generate the autocompletion script for the specified shell - -### Synopsis - -Generate the autocompletion script for grimoire for the specified shell. -See each sub-command's help for details on how to use the generated script. - - -### Options - -``` - -h, --help help for completion -``` - -### SEE ALSO - -* [grimoire](grimoire.md) - Grimoire - A CLI tool for managing and using GenAI prompts -* [grimoire completion bash](grimoire_completion_bash.md) - Generate the autocompletion script for bash -* [grimoire completion fish](grimoire_completion_fish.md) - Generate the autocompletion script for fish -* [grimoire completion powershell](grimoire_completion_powershell.md) - Generate the autocompletion script for powershell -* [grimoire completion zsh](grimoire_completion_zsh.md) - Generate the autocompletion script for zsh - -###### Auto generated by spf13/cobra on 9-Nov-2024 diff --git a/docs/content/grimoire_completion_powershell.md b/docs/content/grimoire_completion_powershell.md deleted file mode 100644 index e27d5e8..0000000 --- a/docs/content/grimoire_completion_powershell.md +++ /dev/null @@ -1,32 +0,0 @@ -## grimoire completion powershell - -Generate the autocompletion script for powershell - -### Synopsis - -Generate the autocompletion script for powershell. - -To load completions in your current shell session: - - grimoire completion powershell | Out-String | Invoke-Expression - -To load completions for every new session, add the output of the above command -to your powershell profile. - - -``` -grimoire completion powershell [flags] -``` - -### Options - -``` - -h, --help help for powershell - --no-descriptions disable completion descriptions -``` - -### SEE ALSO - -* [grimoire completion](grimoire_completion.md) - Generate the autocompletion script for the specified shell - -###### Auto generated by spf13/cobra on 9-Nov-2024 diff --git a/docs/content/grimoire_copy.md b/docs/content/grimoire_copy.md deleted file mode 100644 index 8c21a78..0000000 --- a/docs/content/grimoire_copy.md +++ /dev/null @@ -1,19 +0,0 @@ -## grimoire copy - -Copy the prompt to the clipboard - -``` -grimoire copy [prompt name] [flags] -``` - -### Options - -``` - -h, --help help for copy -``` - -### SEE ALSO - -* [grimoire](grimoire.md) - Grimoire - A CLI tool for managing and using GenAI prompts - -###### Auto generated by spf13/cobra on 9-Nov-2024 diff --git a/docs/content/grimoire_delete.md b/docs/content/grimoire_delete.md deleted file mode 100644 index d5a2827..0000000 --- a/docs/content/grimoire_delete.md +++ /dev/null @@ -1,19 +0,0 @@ -## grimoire delete - -Delete the prompt - -``` -grimoire delete [prompt name] [flags] -``` - -### Options - -``` - -h, --help help for delete -``` - -### SEE ALSO - -* [grimoire](grimoire.md) - Grimoire - A CLI tool for managing and using GenAI prompts - -###### Auto generated by spf13/cobra on 9-Nov-2024 diff --git a/docs/content/grimoire_edit.md b/docs/content/grimoire_edit.md deleted file mode 100644 index b61a8a0..0000000 --- a/docs/content/grimoire_edit.md +++ /dev/null @@ -1,19 +0,0 @@ -## grimoire edit - -Edit the prompt in the chosen editor - -``` -grimoire edit [prompt name] [flags] -``` - -### Options - -``` - -h, --help help for edit -``` - -### SEE ALSO - -* [grimoire](grimoire.md) - Grimoire - A CLI tool for managing and using GenAI prompts - -###### Auto generated by spf13/cobra on 9-Nov-2024 diff --git a/docs/content/grimoire_generate.md b/docs/content/grimoire_generate.md deleted file mode 100644 index a1d95fc..0000000 --- a/docs/content/grimoire_generate.md +++ /dev/null @@ -1,19 +0,0 @@ -## grimoire generate - -Get generation from Ollama - -``` -grimoire generate [prompt] [flags] -``` - -### Options - -``` - -h, --help help for generate -``` - -### SEE ALSO - -* [grimoire](grimoire.md) - Grimoire - A CLI tool for managing and using GenAI prompts - -###### Auto generated by spf13/cobra on 9-Nov-2024 diff --git a/docs/content/grimoire_list.md b/docs/content/grimoire_list.md deleted file mode 100644 index a4af097..0000000 --- a/docs/content/grimoire_list.md +++ /dev/null @@ -1,19 +0,0 @@ -## grimoire list - -List files in the target directory - -``` -grimoire list [directory] [flags] -``` - -### Options - -``` - -h, --help help for list -``` - -### SEE ALSO - -* [grimoire](grimoire.md) - Grimoire - A CLI tool for managing and using GenAI prompts - -###### Auto generated by spf13/cobra on 9-Nov-2024 diff --git a/docs/content/grimoire_say.md b/docs/content/grimoire_say.md deleted file mode 100644 index fac1f43..0000000 --- a/docs/content/grimoire_say.md +++ /dev/null @@ -1,23 +0,0 @@ -## grimoire say - -Print Grimoire logo - -### Synopsis - -Print out the Grimoire logo. - -``` -grimoire say [flags] -``` - -### Options - -``` - -h, --help help for say -``` - -### SEE ALSO - -* [grimoire](grimoire.md) - Grimoire - A CLI tool for managing and using GenAI prompts - -###### Auto generated by spf13/cobra on 9-Nov-2024 diff --git a/docs/themes/hugo-book b/docs/themes/hugo-book new file mode 160000 index 0000000..7c78a39 --- /dev/null +++ b/docs/themes/hugo-book @@ -0,0 +1 @@ +Subproject commit 7c78a39c531aa2492ed7e92f2ce9dfb2c8c0d3fa diff --git a/src/cmd/docs.go b/src/cmd/docs.go index 2a58bb6..763d3c3 100644 --- a/src/cmd/docs.go +++ b/src/cmd/docs.go @@ -1,24 +1,149 @@ package cmd import ( + "fmt" + "os" + "path/filepath" + "strings" + "time" + "github.com/spf13/cobra" - "github.com/spf13/cobra/doc" + "github.com/spf13/pflag" ) -func GenerateDocs(rootCmd *cobra.Command) error { - // Generate markdown files - return doc.GenMarkdownTree(rootCmd, "./docs/content") -} +func generateHugoDoc(cmd *cobra.Command, baseDir string, weight int) error { + // Create directory for the command + cmdPath := strings.ReplaceAll(cmd.CommandPath(), " ", "/") + cmdDir := filepath.Join(baseDir, cmdPath) + if err := os.MkdirAll(cmdDir, 0755); err != nil { + return err + } -func init() { - rootCmd.AddCommand(docsCmd) + // Create _index.md in the command's directory + filename := filepath.Join(cmdDir, "_index.md") + f, err := os.Create(filename) + if err != nil { + return err + } + defer f.Close() + + // Write Hugo front matter + fmt.Fprintf(f, `--- +title: "%s" +description: "%s" +weight: %d +date: %s +draft: false +--- + +`, cmd.Name(), cmd.Short, weight, time.Now().Format("2006-01-02")) + + // Write command description + fmt.Fprintf(f, "# %s\n\n", cmd.CommandPath()) + if cmd.Long != "" { + fmt.Fprintf(f, "%s\n\n", cmd.Long) + } else { + fmt.Fprintf(f, "%s\n\n", cmd.Short) + } + + // Write usage + fmt.Fprintf(f, "## Usage\n\n```bash\n%s\n```\n\n", cmd.UseLine()) + + // Write examples if any + if cmd.Example != "" { + fmt.Fprintf(f, "## Examples\n\n```bash\n%s\n```\n\n", cmd.Example) + } + + // Write flags if any + if cmd.HasAvailableFlags() { + fmt.Fprintf(f, "## Flags\n\n") + fmt.Fprintf(f, "| Flag | Description | Default |\n") + fmt.Fprintf(f, "|------|-------------|----------|\n") + cmd.Flags().VisitAll(func(flag *pflag.Flag) { + defaultValue := flag.DefValue + if defaultValue == "" { + defaultValue = "-" + } + fmt.Fprintf(f, "| `--%s` | %s | `%s` |\n", flag.Name, flag.Usage, defaultValue) + }) + fmt.Fprintf(f, "\n") + } + + // Write subcommands if any + if cmd.HasSubCommands() { + fmt.Fprintf(f, "## Subcommands\n\n") + for _, subCmd := range cmd.Commands() { + if !subCmd.Hidden { + fmt.Fprintf(f, "* [%s](./%s/) - %s\n", + subCmd.Name(), + strings.ReplaceAll(subCmd.Name(), " ", "-"), + subCmd.Short) + } + } + fmt.Fprintf(f, "\n") + } + + // Generate docs for each subcommand + for i, subCmd := range cmd.Commands() { + if !subCmd.Hidden { + if err := generateHugoDoc(subCmd, baseDir, weight+i+1); err != nil { + return err + } + } + } + + return nil } var docsCmd = &cobra.Command{ - Use: "docs", - Short: "Generate markdown documentation", - Hidden: true, + Use: "docs", + Short: "Generate documentation for grimoire", RunE: func(cmd *cobra.Command, args []string) error { - return GenerateDocs(rootCmd) + // Create main commands directory and index + docsDir := "./docs/content/" + if err := os.MkdirAll(docsDir, 0755); err != nil { + return err + } + + // Create main index file + index, err := os.Create(filepath.Join(docsDir, "_index.md")) + if err != nil { + return err + } + defer index.Close() + + // Write main index front matter + fmt.Fprintf(index, `--- +title: "Command Reference" +description: "Complete reference for Grimoire CLI commands" +weight: 1 +date: %s +draft: false +--- + +# Command Reference + +This section contains the complete reference for all Grimoire CLI commands. + +## Available Commands + +`, time.Now().Format("2006-01-02")) + + // List all top-level commands in the index + for _, cmd := range rootCmd.Commands() { + if !cmd.Hidden { + fmt.Fprintf(index, "* [%s](grimoire/%s/) - %s\n", + cmd.Name(), + cmd.Name(), + cmd.Short) + } + } + + // Generate docs for root command and all its children + return generateHugoDoc(rootCmd, docsDir, 1) }, } + +func init() { + rootCmd.AddCommand(docsCmd) +}