Skip to content

Commit 2130b1d

Browse files
committed
feat(cli): add manual command and restructure docs
Add `astro manual [protocol]` command that renders CLI reference docs in the terminal using salt/printer markdown rendering. Docs are embedded at compile time via go:embed. Restructure docs/ into cli/, reference/, guides/, and pics/ for clear separation of CLI manuals, Go API reference, educational content, and conformance statements.
1 parent d3e48ba commit 2130b1d

25 files changed

Lines changed: 3476 additions & 3378 deletions

cli/manual.go

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package cli
2+
3+
import (
4+
"embed"
5+
"fmt"
6+
"strings"
7+
8+
"github.com/raystack/salt/cli/printer"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
// protocols maps CLI protocol names to their doc filenames.
13+
var protocols = map[string]string{
14+
"spp": "spp.md",
15+
"epp": "epp.md",
16+
"tm": "tm.md",
17+
"tc": "tc.md",
18+
"time": "time.md",
19+
"cadu": "cadu.md",
20+
"cltu": "cltu.md",
21+
}
22+
23+
func manualCmd(docsFS embed.FS) *cobra.Command {
24+
cmd := &cobra.Command{
25+
Use: "manual [protocol]",
26+
Short: "Display protocol reference manual",
27+
Long: "Display the CLI reference manual for a protocol. Run without arguments to list available topics.",
28+
Annotations: map[string]string{
29+
"group": "help",
30+
},
31+
ValidArgs: protocolNames(),
32+
Args: cobra.MaximumNArgs(1),
33+
RunE: func(cmd *cobra.Command, args []string) error {
34+
if len(args) == 0 {
35+
return printManualIndex()
36+
}
37+
return printManual(docsFS, args[0])
38+
},
39+
}
40+
41+
return cmd
42+
}
43+
44+
func printManualIndex() error {
45+
var sb strings.Builder
46+
sb.WriteString("# Astro Manual\n\n")
47+
sb.WriteString("Available protocol manuals:\n\n")
48+
sb.WriteString("| Protocol | Command |\n")
49+
sb.WriteString("|----------|---------|\n")
50+
sb.WriteString("| Space Packet Protocol | `astro manual spp` |\n")
51+
sb.WriteString("| Encapsulation Packet Protocol | `astro manual epp` |\n")
52+
sb.WriteString("| TM Transfer Frames | `astro manual tm` |\n")
53+
sb.WriteString("| TC Transfer Frames | `astro manual tc` |\n")
54+
sb.WriteString("| Time Code Formats | `astro manual time` |\n")
55+
sb.WriteString("| Channel Access Data Units | `astro manual cadu` |\n")
56+
sb.WriteString("| Command Link Transmission Units | `astro manual cltu` |\n")
57+
58+
out, err := printer.Markdown(sb.String())
59+
if err != nil {
60+
return err
61+
}
62+
fmt.Print(out)
63+
return nil
64+
}
65+
66+
func printManual(docsFS embed.FS, protocol string) error {
67+
filename, ok := protocols[protocol]
68+
if !ok {
69+
return fmt.Errorf("unknown protocol %q — run 'astro manual' to see available topics", protocol)
70+
}
71+
72+
content, err := docsFS.ReadFile("docs/cli/" + filename)
73+
if err != nil {
74+
return fmt.Errorf("reading manual for %s: %w", protocol, err)
75+
}
76+
77+
out, err := printer.Markdown(string(content))
78+
if err != nil {
79+
return err
80+
}
81+
fmt.Print(out)
82+
return nil
83+
}
84+
85+
func protocolNames() []string {
86+
names := make([]string, 0, len(protocols))
87+
for k := range protocols {
88+
names = append(names, k)
89+
}
90+
return names
91+
}

cli/root.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package cli
22

33
import (
4+
"embed"
5+
46
"github.com/raystack/salt/cli/commander"
57
"github.com/spf13/cobra"
68
)
79

810
// New creates the root command for the astro CLI.
9-
func New() *cobra.Command {
11+
func New(docsFS embed.FS) *cobra.Command {
1012
cmd := &cobra.Command{
1113
Use: "astro <command> <subcommand> [flags]",
1214
Short: "CCSDS and ECSS space communication toolkit",
@@ -26,6 +28,7 @@ func New() *cobra.Command {
2628
cmd.AddCommand(tcCmd())
2729
cmd.AddCommand(caduCmd())
2830
cmd.AddCommand(cltuCmd())
31+
cmd.AddCommand(manualCmd(docsFS))
2932

3033
mgr := commander.New(cmd)
3134
mgr.Init()

docs/cop.md

Lines changed: 0 additions & 283 deletions
This file was deleted.

0 commit comments

Comments
 (0)