mirror of
https://github.com/Dvorinka/Devour.git
synced 2026-06-03 20:13:03 +00:00
update
This commit is contained in:
+67
-95
@@ -1,118 +1,90 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var languagesFormat string
|
||||
|
||||
var languagesCmd = &cobra.Command{
|
||||
Use: "languages",
|
||||
Short: "Show supported languages and their mappings",
|
||||
Long: `Display all supported languages for the 'devour get' command
|
||||
along with their base URLs and examples.
|
||||
|
||||
This helps you discover what documentation sources are available
|
||||
and how to reference them quickly.`,
|
||||
Short: "Show supported languages and aliases",
|
||||
Long: `Display all supported languages for 'devour get' and 'devour ask'
|
||||
with aliases and starter examples.`,
|
||||
RunE: runLanguages,
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(languagesCmd)
|
||||
languagesCmd.Flags().StringVar(&languagesFormat, "format", "text", "output format (text, json)")
|
||||
}
|
||||
|
||||
type languageInfo struct {
|
||||
Canonical string `json:"canonical"`
|
||||
Aliases []string `json:"aliases"`
|
||||
Example string `json:"example"`
|
||||
Source string `json:"source"`
|
||||
}
|
||||
|
||||
func runLanguages(cmd *cobra.Command, args []string) error {
|
||||
fmt.Println("🌐 Devour Supported Languages")
|
||||
fmt.Println("═══════════════════════════════════════════════════════════════")
|
||||
fmt.Println()
|
||||
|
||||
languages := []struct {
|
||||
langs []string
|
||||
url string
|
||||
examples []string
|
||||
}{
|
||||
{
|
||||
langs: []string{"go", "golang"},
|
||||
url: "https://pkg.go.dev/{package}",
|
||||
examples: []string{"devour get go http", "devour get go fmt", "devour get golang json"},
|
||||
},
|
||||
{
|
||||
langs: []string{"rust"},
|
||||
url: "https://docs.rs/{crate}/latest/{crate}/",
|
||||
examples: []string{"devour get rust tokio", "devour get rust serde", "devour get rust clap"},
|
||||
},
|
||||
{
|
||||
langs: []string{"python", "py"},
|
||||
url: "https://docs.python.org/3/library/{module}.html",
|
||||
examples: []string{"devour get python asyncio", "devour get py requests", "devour get python stdlib"},
|
||||
},
|
||||
{
|
||||
langs: []string{"java"},
|
||||
url: "https://docs.oracle.com/javase/8/docs/api/{package}.html",
|
||||
examples: []string{"devour get java string", "devour get java arraylist"},
|
||||
},
|
||||
{
|
||||
langs: []string{"spring"},
|
||||
url: "https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#{section}",
|
||||
examples: []string{"devour get spring boot", "devour get spring testing"},
|
||||
},
|
||||
{
|
||||
langs: []string{"typescript", "ts"},
|
||||
url: "https://www.typescriptlang.org/docs/handbook/{topic}.html",
|
||||
examples: []string{"devour get typescript interfaces", "devour get ts decorators"},
|
||||
},
|
||||
{
|
||||
langs: []string{"react"},
|
||||
url: "https://react.dev/reference/react/{feature}",
|
||||
examples: []string{"devour get react hooks", "devour get react components", "devour get react state"},
|
||||
},
|
||||
{
|
||||
langs: []string{"vue"},
|
||||
url: "https://vuejs.org/guide/{topic}.html",
|
||||
examples: []string{"devour get vue components", "devour get vue reactivity"},
|
||||
},
|
||||
{
|
||||
langs: []string{"nuxt"},
|
||||
url: "https://nuxt.com/docs/guide/{topic}",
|
||||
examples: []string{"devour get nuxt routing", "devour get nuxt middleware"},
|
||||
},
|
||||
{
|
||||
langs: []string{"docker"},
|
||||
url: "https://docs.docker.com/{topic}",
|
||||
examples: []string{"devour get docker compose", "devour get docker build", "devour get docker networking"},
|
||||
},
|
||||
{
|
||||
langs: []string{"cloudflare", "cf"},
|
||||
url: "https://developers.cloudflare.com/{topic}",
|
||||
examples: []string{"devour get cloudflare workers", "devour get cf pages", "devour get cloudflare dns"},
|
||||
},
|
||||
{
|
||||
langs: []string{"astro"},
|
||||
url: "https://docs.astro.build/en/guides/{topic}",
|
||||
examples: []string{"devour get astro routing", "devour get astro components"},
|
||||
},
|
||||
rows := []languageInfo{
|
||||
{Canonical: "go", Aliases: []string{"go", "golang"}, Example: "devour get go http", Source: "pkg.go.dev"},
|
||||
{Canonical: "rust", Aliases: []string{"rust"}, Example: "devour get rust tokio", Source: "docs.rs"},
|
||||
{Canonical: "python", Aliases: []string{"python", "py"}, Example: "devour get python asyncio", Source: "docs.python.org"},
|
||||
{Canonical: "java", Aliases: []string{"java"}, Example: "devour get java string", Source: "docs.oracle.com"},
|
||||
{Canonical: "spring", Aliases: []string{"spring"}, Example: "devour get spring mcp", Source: "docs.spring.io"},
|
||||
{Canonical: "typescript", Aliases: []string{"typescript", "ts"}, Example: "devour get ts interfaces", Source: "typescriptlang.org"},
|
||||
{Canonical: "react", Aliases: []string{"react"}, Example: "devour get react hooks", Source: "react.dev"},
|
||||
{Canonical: "vue", Aliases: []string{"vue"}, Example: "devour get vue reactivity", Source: "vuejs.org"},
|
||||
{Canonical: "nuxt", Aliases: []string{"nuxt"}, Example: "devour get nuxt routing", Source: "nuxt.com"},
|
||||
{Canonical: "docker", Aliases: []string{"docker"}, Example: "devour get docker compose", Source: "docs.docker.com"},
|
||||
{Canonical: "cloudflare", Aliases: []string{"cloudflare", "cf"}, Example: "devour get cloudflare workers", Source: "developers.cloudflare.com"},
|
||||
{Canonical: "astro", Aliases: []string{"astro"}, Example: "devour get astro components", Source: "docs.astro.build"},
|
||||
{Canonical: "csharp", Aliases: []string{"csharp", "cs"}, Example: "devour get csharp regex", Source: "learn.microsoft.com"},
|
||||
{Canonical: "kotlin", Aliases: []string{"kotlin", "kt"}, Example: "devour get kotlin strings", Source: "kotlinlang.org"},
|
||||
{Canonical: "php", Aliases: []string{"php"}, Example: "devour get php pcre", Source: "php.net"},
|
||||
{Canonical: "ruby", Aliases: []string{"ruby", "rb"}, Example: "devour get ruby Regexp", Source: "ruby-doc.org"},
|
||||
{Canonical: "elixir", Aliases: []string{"elixir", "ex"}, Example: "devour get elixir String", Source: "hexdocs.pm"},
|
||||
{Canonical: "nextjs", Aliases: []string{"next", "nextjs"}, Example: "devour get nextjs routing", Source: "nextjs.org"},
|
||||
{Canonical: "svelte", Aliases: []string{"svelte"}, Example: "devour get svelte kit", Source: "svelte.dev"},
|
||||
{Canonical: "angular", Aliases: []string{"angular", "ng"}, Example: "devour get angular http", Source: "angular.dev"},
|
||||
{Canonical: "remix", Aliases: []string{"remix"}, Example: "devour get remix routes", Source: "v2.remix.run"},
|
||||
{Canonical: "solid", Aliases: []string{"solid", "solidjs"}, Example: "devour get solid router", Source: "github.com/solidjs/solid-docs"},
|
||||
{Canonical: "express", Aliases: []string{"express", "expressjs"}, Example: "devour get express middleware", Source: "expressjs.com"},
|
||||
}
|
||||
|
||||
for _, lang := range languages {
|
||||
fmt.Printf("🔷 %s\n", strings.Join(lang.langs, ", "))
|
||||
fmt.Printf(" URL: %s\n", lang.url)
|
||||
fmt.Printf(" Examples:\n")
|
||||
for _, example := range lang.examples {
|
||||
fmt.Printf(" • %s\n", example)
|
||||
switch strings.ToLower(strings.TrimSpace(languagesFormat)) {
|
||||
case "json":
|
||||
out := struct {
|
||||
Count int `json:"count"`
|
||||
Languages []languageInfo `json:"languages"`
|
||||
}{
|
||||
Count: len(rows),
|
||||
Languages: rows,
|
||||
}
|
||||
fmt.Println()
|
||||
enc := json.NewEncoder(cmd.OutOrStdout())
|
||||
enc.SetIndent("", " ")
|
||||
return enc.Encode(out)
|
||||
case "text", "":
|
||||
printLanguagesText(cmd.OutOrStdout(), rows)
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("unsupported format: %s", languagesFormat)
|
||||
}
|
||||
|
||||
fmt.Println("💡 Pro Tips:")
|
||||
fmt.Println(" • Use 'devour get <language> help' for language-specific help")
|
||||
fmt.Println(" • Add --format markdown for enhanced documentation")
|
||||
fmt.Println(" • Most languages support common aliases (e.g., py → python)")
|
||||
fmt.Println()
|
||||
fmt.Println("🚀 Quick Start:")
|
||||
fmt.Println(" devour get go http --format markdown")
|
||||
fmt.Println(" devour get python asyncio")
|
||||
fmt.Println(" devour get react hooks")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func printLanguagesText(out io.Writer, rows []languageInfo) {
|
||||
_, _ = fmt.Fprintln(out, "Devour Supported Languages")
|
||||
_, _ = fmt.Fprintln(out, "============================================")
|
||||
_, _ = fmt.Fprintln(out)
|
||||
for _, row := range rows {
|
||||
_, _ = fmt.Fprintf(out, "- %s (%s)\n", row.Canonical, strings.Join(row.Aliases, ", "))
|
||||
_, _ = fmt.Fprintf(out, " source: %s\n", row.Source)
|
||||
_, _ = fmt.Fprintf(out, " example: %s\n\n", row.Example)
|
||||
}
|
||||
_, _ = fmt.Fprintln(out, "Tip: use 'devour get <language> <keyword> --format markdown' for readable output.")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user