Skip to content

Commit

Permalink
feat: add caddy inspect
Browse files Browse the repository at this point in the history
  • Loading branch information
scmmishra committed Jul 27, 2024
1 parent 7308b46 commit cf07378
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions cmd/slick/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"

"github.com/scmmishra/slick-deploy/internal/caddy"
"github.com/scmmishra/slick-deploy/internal/config"
"github.com/scmmishra/slick-deploy/internal/deploy"
"github.com/scmmishra/slick-deploy/internal/docker"
Expand Down Expand Up @@ -111,6 +112,25 @@ var logsCmd = &cobra.Command{
},
}

var caddyInspectCmd = &cobra.Command{
Use: "caddy-inspect",
Short: "Inspect the current Caddy configuration",
Long: `The caddy-inspect command retrieves and displays the current Caddy configuration.`,
Run: func(cmd *cobra.Command, args []string) {
cfgPath, _ := cmd.Flags().GetString("config")

// Load configuration
cfg, err := config.LoadConfig(cfgPath)
if err != nil {
cmd.PrintErrf("Failed to load config: %v", err)
os.Exit(1)
}

caddyConfig := caddy.ConvertToCaddyfile(cfg.Caddy, 0) // Use 0 as port since we're just inspecting
fmt.Println(caddyConfig)
},
}

// Execute adds all child commands to the root command sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
Expand All @@ -132,6 +152,9 @@ func init() {
logsCmd.Flags().StringP("config", "c", "slick.yml", "Path to the configuration file")
logsCmd.Flags().StringP("tail", "t", "all", "Tail logs")
rootCmd.AddCommand(logsCmd)

caddyInspectCmd.Flags().StringP("config", "c", "slick.yml", "Path to the configuration file")
rootCmd.AddCommand(caddyInspectCmd)
}

func main() {
Expand Down

0 comments on commit cf07378

Please sign in to comment.