-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.go
76 lines (66 loc) · 2.27 KB
/
test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//go:build test
package main
import (
"embed"
"log/slog"
"os"
"path/filepath"
"github.com/harish876/hypefx/internal/cli/commands"
"github.com/harish876/hypefx/internal/cli/commands/add"
"github.com/harish876/hypefx/internal/cli/commands/build"
"github.com/harish876/hypefx/internal/cli/commands/generate"
"github.com/harish876/hypefx/internal/cli/commands/set"
"github.com/harish876/hypefx/internal/cli/commands/unset"
"github.com/harish876/hypefx/internal/cli/commands/version"
"github.com/harish876/hypefx/internal/utils"
"github.com/spf13/cobra"
)
//go:embed components/*
var components embed.FS
func main() {
loggerConfig := utils.FromConfig(filepath.Join("tmp", "hypefx.log"))
jsonHandler := slog.NewJSONHandler(loggerConfig, &slog.HandlerOptions{
AddSource: true,
Level: utils.FromLogLevel("debug"),
})
slog.SetDefault(slog.New(jsonHandler))
rootCmd := &cobra.Command{
Use: "hype-test",
Short: "A simple CLI tool to bootstrap Go + HTMX + Templ Projects.",
Run: func(cmd *cobra.Command, args []string) {
version.Welcome(cmd, args, map[string]string{
"buildEnv": "test",
})
},
ValidArgs: []string{"generate", "build", "set", "unset", "add"},
}
//this needs access to components.to be refactored
var addCmd = &cobra.Command{
Use: "add [compoent_name] [project_name/module_name](optional)",
Short: "Add a new component from the component library",
Long: `Add a new component from the component library , and customise it as per your liking`,
Args: cobra.ExactArgs(1),
Example: "hype add grid",
ValidArgs: []string{"notfound", "grid", "input", "dropdown", "notification"},
Run: func(cmd *cobra.Command, args []string) {
add.Add(cmd, args, components)
},
}
//Init Command Flags
slog.Info("CLI Initialization done. Build tag is test")
rootCmd.Flags().BoolP("version", "v", false, "Display CLI Version")
set.InitFlags()
//add autocompletion
addCmd.CompletionOptions.DisableDefaultCmd = true
// Add Command
rootCmd.AddCommand(generate.GenerateCmd)
rootCmd.AddCommand(set.SetCmd)
rootCmd.AddCommand(unset.UnsetCmd)
rootCmd.AddCommand(addCmd)
rootCmd.AddCommand(build.BuildCmd)
rootCmd.AddCommand(commands.CompletionCmd)
if err := rootCmd.Execute(); err != nil {
slog.Error("rootCmd", err)
os.Exit(1)
}
}