diff --git a/cmd/cli.go b/cmd/cli.go index c73990d..d88acf4 100644 --- a/cmd/cli.go +++ b/cmd/cli.go @@ -91,6 +91,21 @@ func addEmbeddedFileCommands() { Use: strings.ReplaceAll(dirPath, string(os.PathSeparator), " "), Short: fmt.Sprintf("Commands for files in %s", dirPath), } + dirCmd.Run = func(_ *cobra.Command, _ []string) { + if daemon { + httpInput := httpserver.HTTPInput{ + BinaryName: filepath.Base(os.Args[0]), + EmbeddedFolder: &contracts, + EmbeddedPath: "contracts", + EmbeddedSubDir: dirPath, + } + if err := httpserver.StartHTTPServer(httpInput); err != nil { + log.Printf("Failed to start HTTP server: %v\n", err) + os.Exit(1) + } + return + } + } dirCommands[dirPath] = dirCmd parentCmd.AddCommand(dirCmd) } diff --git a/cmd/httpserver/http.go b/cmd/httpserver/http.go index 8f232f2..8d2215e 100644 --- a/cmd/httpserver/http.go +++ b/cmd/httpserver/http.go @@ -14,10 +14,29 @@ type HTTPInput struct { BinaryName string EmbeddedFolder *embed.FS EmbeddedPath string + EmbeddedSubDir string Path string FileName string } +const openapiCSS = ` + +` + // StartSHTTPrver starts an HTTP server that serves the OpenAPI documentation via Stoplight Elements. // The documentation is available at the `/slang` endpoint. func StartHTTPServer(input HTTPInput) error { @@ -48,11 +67,12 @@ func StartHTTPServer(input HTTPInput) error {