tenseleyflow/shithub / 730b0d2

Browse files

Add shithubd entrypoint with cobra subcommands and stubs for later sprints

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
730b0d291794a2789e17e6a7276f97685fcf45f7
Parents
8f9236b
Tree
0b8ce4e

5 changed files

StatusFile+-
A cmd/shithubd/main.go 12 0
A cmd/shithubd/root.go 43 0
A cmd/shithubd/stubs.go 22 0
A cmd/shithubd/version.go 24 0
A cmd/shithubd/web.go 22 0
cmd/shithubd/main.goadded
@@ -0,0 +1,12 @@
1
+// SPDX-License-Identifier: AGPL-3.0-or-later
2
+
3
+// Command shithubd is the entrypoint binary for shithub.
4
+//
5
+// It exposes web/ssh/worker/migrate/admin subcommands. See `shithubd --help`
6
+// for the full list, and `.docs/sprints/` for which subcommands are
7
+// implemented in which sprint.
8
+package main
9
+
10
+func main() {
11
+	Execute()
12
+}
cmd/shithubd/root.goadded
@@ -0,0 +1,43 @@
1
+// SPDX-License-Identifier: AGPL-3.0-or-later
2
+
3
+package main
4
+
5
+import (
6
+	"fmt"
7
+	"os"
8
+
9
+	"github.com/spf13/cobra"
10
+)
11
+
12
+var rootCmd = &cobra.Command{
13
+	Use:           "shithubd",
14
+	Short:         "shithub server: web, ssh, worker, and admin tooling",
15
+	Long:          "shithubd is the entrypoint binary for shithub — a feature-complete, AGPL-licensed clone of GitHub.\nSubcommands cover the HTTP web server, the SSH dispatcher, background workers, migrations, and operational helpers.",
16
+	SilenceUsage:  true,
17
+	SilenceErrors: true,
18
+}
19
+
20
+// Execute runs the root command and exits non-zero on error.
21
+func Execute() {
22
+	if err := rootCmd.Execute(); err != nil {
23
+		fmt.Fprintln(os.Stderr, "shithubd:", err)
24
+		os.Exit(1)
25
+	}
26
+}
27
+
28
+func init() {
29
+	rootCmd.AddCommand(versionCmd)
30
+	rootCmd.AddCommand(webCmd)
31
+
32
+	// Stubs for subcommands implemented in later sprints. They surface in
33
+	// `--help` so the operator-facing interface is discoverable from day one.
34
+	rootCmd.AddCommand(stubCmd("migrate", "Run database migrations", "S01"))
35
+	rootCmd.AddCommand(stubCmd("seed", "Load development seed data", "S01"))
36
+	rootCmd.AddCommand(stubCmd("worker", "Run background workers", "S14"))
37
+	rootCmd.AddCommand(stubCmd("ssh-authkeys", "AuthorizedKeysCommand handler", "S07"))
38
+	rootCmd.AddCommand(stubCmd("ssh-shell", "Forced SSH shell dispatcher", "S07/S13"))
39
+	rootCmd.AddCommand(stubCmd("storage", "Storage health checks", "S04"))
40
+	rootCmd.AddCommand(stubCmd("hook", "Git hook entrypoint", "S14"))
41
+	rootCmd.AddCommand(stubCmd("admin", "Site-admin CLI", "S34"))
42
+	rootCmd.AddCommand(stubCmd("config", "Config introspection", "S03"))
43
+}
cmd/shithubd/stubs.goadded
@@ -0,0 +1,22 @@
1
+// SPDX-License-Identifier: AGPL-3.0-or-later
2
+
3
+package main
4
+
5
+import (
6
+	"fmt"
7
+
8
+	"github.com/spf13/cobra"
9
+)
10
+
11
+// stubCmd returns a placeholder cobra command for subcommands scheduled in
12
+// later sprints. The sprint identifier is surfaced in the error so an
13
+// operator who hits the stub knows which sprint adds the implementation.
14
+func stubCmd(name, short, sprint string) *cobra.Command {
15
+	return &cobra.Command{
16
+		Use:   name,
17
+		Short: fmt.Sprintf("%s (planned in %s)", short, sprint),
18
+		RunE: func(cmd *cobra.Command, args []string) error {
19
+			return fmt.Errorf("%s: not yet implemented (planned in sprint %s)", name, sprint)
20
+		},
21
+	}
22
+}
cmd/shithubd/version.goadded
@@ -0,0 +1,24 @@
1
+// SPDX-License-Identifier: AGPL-3.0-or-later
2
+
3
+package main
4
+
5
+import (
6
+	"fmt"
7
+	"runtime"
8
+
9
+	"github.com/spf13/cobra"
10
+
11
+	"github.com/tenseleyFlow/shithub/internal/version"
12
+)
13
+
14
+var versionCmd = &cobra.Command{
15
+	Use:   "version",
16
+	Short: "Print version, commit, build time, and Go runtime",
17
+	Run: func(cmd *cobra.Command, args []string) {
18
+		fmt.Printf("shithubd %s\n", version.Version)
19
+		fmt.Printf("  commit: %s\n", version.Commit)
20
+		fmt.Printf("  built:  %s\n", version.BuiltAt)
21
+		fmt.Printf("  go:     %s\n", runtime.Version())
22
+		fmt.Printf("  os:     %s/%s\n", runtime.GOOS, runtime.GOARCH)
23
+	},
24
+}
cmd/shithubd/web.goadded
@@ -0,0 +1,22 @@
1
+// SPDX-License-Identifier: AGPL-3.0-or-later
2
+
3
+package main
4
+
5
+import (
6
+	"github.com/spf13/cobra"
7
+
8
+	"github.com/tenseleyFlow/shithub/internal/web"
9
+)
10
+
11
+var webCmd = &cobra.Command{
12
+	Use:   "web",
13
+	Short: "Run the shithub HTTP web server",
14
+	RunE: func(cmd *cobra.Command, args []string) error {
15
+		addr, _ := cmd.Flags().GetString("addr")
16
+		return web.Run(cmd.Context(), web.Options{Addr: addr})
17
+	},
18
+}
19
+
20
+func init() {
21
+	webCmd.Flags().StringP("addr", "a", ":8080", "Address to bind the web server to")
22
+}