Skip to content

Commit aa2f0ea

Browse files
committed
feat: add env command and config support
1 parent f7f4349 commit aa2f0ea

File tree

5 files changed

+60
-1
lines changed

5 files changed

+60
-1
lines changed

bootstrap/boot.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package bootstrap
22

33
import (
4+
"github.com/pubgo/fastcommit/cmds/envcmd"
45
"log/slog"
56
"os"
67

@@ -56,6 +57,7 @@ func Main() {
5657
di.Provide(tagcmd.New)
5758
di.Provide(config.Load[ConfigProvider])
5859
di.Provide(utils.NewOpenaiClient)
60+
di.Provide(envcmd.New)
5961
di.Provide(fastcommit.New)
6062
di.Inject(func(cmd *fastcommit.Command) { cmd.Run() })
6163
}

cmds/envcmd/cmd.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package envcmd
2+
3+
import (
4+
"context"
5+
6+
"github.com/pubgo/fastcommit/configs"
7+
"github.com/pubgo/funk/assert"
8+
"github.com/pubgo/funk/pretty"
9+
"github.com/pubgo/funk/recovery"
10+
"github.com/samber/lo"
11+
"github.com/urfave/cli/v3"
12+
"gopkg.in/yaml.v3"
13+
)
14+
15+
func New() *cli.Command {
16+
return &cli.Command{
17+
Name: "env",
18+
Usage: "show all envs",
19+
Action: func(ctx context.Context, command *cli.Command) error {
20+
defer recovery.Exit()
21+
var envData = configs.GetEnvConfig()
22+
var envMap = make(map[string]*configs.EnvConfig)
23+
assert.Must(yaml.Unmarshal(envData, &envMap))
24+
for name := range envMap {
25+
envMap[name].Name = name
26+
}
27+
28+
pretty.Println(lo.Values(envMap))
29+
30+
return nil
31+
},
32+
}
33+
}

cmds/tagcmd/cmd.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import (
1717

1818
func New() *cli.Command {
1919
return &cli.Command{
20-
Name: "tag",
20+
Name: "tag",
21+
Usage: "gen tag and push origin",
2122
Action: func(ctx context.Context, command *cli.Command) error {
2223
defer recovery.Exit()
2324
var p = tea.NewProgram(initialModel())

configs/config.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ import (
88
"github.com/pubgo/funk/assert"
99
)
1010

11+
type EnvConfig struct {
12+
Description string `yaml:"description"`
13+
Default string `yaml:"default"`
14+
Name string `yaml:"name"`
15+
Required bool `yaml:"required"`
16+
}
17+
1118
type Config struct {
1219
BranchName string
1320
}
@@ -22,6 +29,9 @@ var branchName = assert.Exit1(utils.RunOutput("git", "rev-parse", "--abbrev-ref"
2229
//go:embed default.yaml
2330
var defaultConfig []byte
2431

32+
//go:embed env.yaml
33+
var envConfig []byte
34+
2535
func GetConfigPath() string {
2636
return configPath
2737
}
@@ -33,3 +43,7 @@ func GetBranchName() string {
3343
func GetDefaultConfig() []byte {
3444
return defaultConfig
3545
}
46+
47+
func GetEnvConfig() []byte {
48+
return envConfig
49+
}

configs/env.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
OPENAI_API_KEY:
2+
description: "OpenAI API Key"
3+
required: true
4+
OPENAI_BASE_URL:
5+
description: "OpenAI Base URL"
6+
default: "https://api.deepseek.com/v1"
7+
OPENAI_MODEL:
8+
description: "OpenAI Model"
9+
default: "deepseek-chat"

0 commit comments

Comments
 (0)