From eadd802f5bf8586f9174dc28a8de384131245c48 Mon Sep 17 00:00:00 2001 From: mochi-yu Date: Sun, 3 Sep 2023 19:46:54 +0900 Subject: [PATCH 1/8] =?UTF-8?q?doc:=20=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89?= =?UTF-8?q?=E3=83=AA=E3=82=B9=E3=83=88=E3=81=AE=E3=83=89=E3=82=AD=E3=83=A5?= =?UTF-8?q?=E3=83=A1=E3=83=B3=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0=20#10?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/command_list.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 doc/command_list.md diff --git a/doc/command_list.md b/doc/command_list.md new file mode 100644 index 0000000..754f615 --- /dev/null +++ b/doc/command_list.md @@ -0,0 +1,12 @@ +## コマンドリスト + +### コマンド +- `suggest`:コミットメッセージの生成 +- `config`:各種の設定 + - 選択肢を出して設定項目を選んでもらう + - 設定項目はAPIキー、日本語/英語、など + +### フラッグ +- `--help` `-h`:CLIのコマンドとオプション一覧を表示 +- `--docs` `-d`:コミットメッセージに関するドキュメント +- `--version` `-v`:アプリのバージョン表示 From 20400acd01b79562dd87441d275e4d2f217000d0 Mon Sep 17 00:00:00 2001 From: mochi-yu Date: Mon, 4 Sep 2023 23:42:09 +0900 Subject: [PATCH 2/8] =?UTF-8?q?fix:=20=E8=A8=AD=E5=AE=9A=E9=A0=85=E7=9B=AE?= =?UTF-8?q?=E3=82=92Toke=E3=81=A7=E3=81=AF=E3=81=AA=E3=81=8FApiKey?= =?UTF-8?q?=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/settings.go | 6 +++--- internal/entity/config.go | 2 +- internal/gateway/openai.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/settings.go b/cmd/settings.go index e7adf54..d953b43 100644 --- a/cmd/settings.go +++ b/cmd/settings.go @@ -14,7 +14,7 @@ var setAPIKeyCmd = &cobra.Command{ Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { config, _ := util.ReadConfig() - config.ChatGptToken = args[0] + config.ChatGptApiKey = args[0] if err := util.WriteConfig(config); err != nil { log.Fatal("Failed to write into config", err) } @@ -30,10 +30,10 @@ var showAPIKeyCmd = &cobra.Command{ if err != nil { log.Fatal("Failed to read config:", err) } - if config.ChatGptToken == "" { + if config.ChatGptApiKey == "" { fmt.Println("API key is not set") } else { - fmt.Println("ChatGPT APIKey:", config.ChatGptToken) + fmt.Println("ChatGPT APIKey:", config.ChatGptApiKey) } }, } diff --git a/internal/entity/config.go b/internal/entity/config.go index 5494020..1456ce4 100644 --- a/internal/entity/config.go +++ b/internal/entity/config.go @@ -1,5 +1,5 @@ package entity type Config struct { - ChatGptToken string `json:"chatGptToken"` + ChatGptApiKey string `json:"chatGptApiKey"` } diff --git a/internal/gateway/openai.go b/internal/gateway/openai.go index ebd70e8..d86d304 100644 --- a/internal/gateway/openai.go +++ b/internal/gateway/openai.go @@ -23,7 +23,7 @@ func NewOpenAIGateway(ctx context.Context) OpenAIGateway { if err != nil { log.Fatalf("Failed to read config: %v", err) } - client := openai.NewClient(config.ChatGptToken) + client := openai.NewClient(config.ChatGptApiKey) return &openAIGateway{client: client, ctx: ctx} } From a62741bde935a82299c2905d4a3689c8deaea256 Mon Sep 17 00:00:00 2001 From: mochi-yu Date: Tue, 5 Sep 2023 01:38:07 +0900 Subject: [PATCH 3/8] =?UTF-8?q?feat:=20`config.yaml`=E3=83=95=E3=82=A1?= =?UTF-8?q?=E3=82=A4=E3=83=AB=E3=81=8C=E7=84=A1=E3=81=91=E3=82=8C=E3=81=B0?= =?UTF-8?q?=E6=96=B0=E8=A6=8F=E3=81=A7=E4=BD=9C=E6=88=90=E3=81=99=E3=82=8B?= =?UTF-8?q?=E5=87=A6=E7=90=86=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.yaml | 1 - util/config.go | 28 +++++++++++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) delete mode 100644 config.yaml diff --git a/config.yaml b/config.yaml deleted file mode 100644 index ad76b5a..0000000 --- a/config.yaml +++ /dev/null @@ -1 +0,0 @@ -chatgpttoken: diff --git a/util/config.go b/util/config.go index 8fcaed5..6342ac3 100644 --- a/util/config.go +++ b/util/config.go @@ -3,6 +3,7 @@ package util import ( "encoding/json" "fmt" + "os" "github.com/cocoide/commitify/internal/entity" "github.com/spf13/viper" @@ -10,36 +11,53 @@ import ( func ReadConfig() (*entity.Config, error) { var result entity.Config + + // configファイルがあるかどうかを確認 + _, err := os.Stat("config.yaml") + if os.IsNotExist(err) { + if _, err := os.Create("config.yaml"); err != nil { + return &result, fmt.Errorf("error creating config file, %s", err.Error()) + } + } + viper.AddConfigPath(".") viper.SetConfigName("config") viper.SetConfigType("yaml") if err := viper.ReadInConfig(); err != nil { - return &result, fmt.Errorf("Error reading config file, %s", err.Error()) + return &result, fmt.Errorf("error reading config file, %s", err.Error()) } if err := viper.Unmarshal(&result); err != nil { - return &result, fmt.Errorf("Unable to decode into struct, %v", err.Error()) + return &result, fmt.Errorf("unable to decode into struct, %v", err.Error()) } return &result, nil } func WriteConfig(config *entity.Config) error { + // configファイルがあるかどうかを確認 + _, err := os.Stat("config.yaml") + if !os.IsNotExist(err) { + if _, err := os.Create("config.yaml"); err != nil { + return fmt.Errorf("error creating config file, %s", err.Error()) + } + } + viper.AddConfigPath(".") viper.SetConfigName("config") viper.SetConfigType("yaml") configMap := make(map[string]interface{}) configBytes, err := json.Marshal(config) if err != nil { - return fmt.Errorf("Error marshalling config: %s", err.Error()) + return fmt.Errorf("error marshalling config: %s", err.Error()) } err = json.Unmarshal(configBytes, &configMap) if err != nil { - return fmt.Errorf("Error unmarshalling config: %s", err.Error()) + return fmt.Errorf("error unmarshalling config: %s", err.Error()) } if err := viper.MergeConfigMap(configMap); err != nil { return err } if err := viper.WriteConfig(); err != nil { - return fmt.Errorf("Error saving config file, %s", err.Error()) + return fmt.Errorf("error saving config file, %s", err.Error()) } return nil } From 6f5d1eb04bbbea5d8861425ce4ea9d30bde82d4b Mon Sep 17 00:00:00 2001 From: mochi-yu Date: Tue, 5 Sep 2023 01:39:29 +0900 Subject: [PATCH 4/8] =?UTF-8?q?fix:=20=E8=A8=AD=E5=AE=9A=E5=91=A8=E3=82=8A?= =?UTF-8?q?=E3=81=AE=E4=B8=8D=E8=A6=81=E3=81=AA=E9=A0=85=E7=9B=AE=E3=82=92?= =?UTF-8?q?=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/suggest.go | 1 - main.go | 12 ------------ util/loadenv.go | 17 ----------------- 3 files changed, 30 deletions(-) delete mode 100644 util/loadenv.go diff --git a/cmd/suggest.go b/cmd/suggest.go index 1ba365b..c63bcfa 100644 --- a/cmd/suggest.go +++ b/cmd/suggest.go @@ -28,7 +28,6 @@ type generateMessages struct { func (m model) Init() tea.Cmd { return func() tea.Msg { - util.LoadEnv() ctx := context.Background() og := gateway.NewOpenAIGateway(ctx) ms := service.NewMessageService(og) diff --git a/main.go b/main.go index 7539cc2..829c11e 100644 --- a/main.go +++ b/main.go @@ -1,21 +1,9 @@ package main import ( - "log" - "github.com/cocoide/commitify/cmd" - "github.com/spf13/viper" ) func main() { - viper.SetConfigName("config") - viper.AddConfigPath(".") - viper.SetConfigType("yaml") - viper.AutomaticEnv() - - if err := viper.ReadInConfig(); err != nil { - log.Println("An error occurred while reading the configuration file:", err) - } - cmd.Execute() } diff --git a/util/loadenv.go b/util/loadenv.go deleted file mode 100644 index ccc7892..0000000 --- a/util/loadenv.go +++ /dev/null @@ -1,17 +0,0 @@ -package util - -import ( - "log" - - "github.com/joho/godotenv" -) - -// Viperを導入したらgodotenvのコードは削除する -func LoadEnv() { - err := godotenv.Load(".env") - if err != nil { - log.Printf("failed to load .env file: %v" + err.Error()) - } else { - // log.Print("success to load .env file") - } -} From 681ba9934265b6defb2c8ba9156dc8e5f9792b2d Mon Sep 17 00:00:00 2001 From: mochi-yu Date: Tue, 5 Sep 2023 01:39:45 +0900 Subject: [PATCH 5/8] =?UTF-8?q?feat:=20config=E9=A0=85=E7=9B=AE=E3=81=AE?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/entity/config.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/entity/config.go b/internal/entity/config.go index 1456ce4..226ac5a 100644 --- a/internal/entity/config.go +++ b/internal/entity/config.go @@ -2,4 +2,6 @@ package entity type Config struct { ChatGptApiKey string `json:"chatGptApiKey"` + UseLanguage string `json:"UseLanguage"` + CommitFormat string `json:"CommitFormat"` } From 91190ba93faa654774833a2e2254a37a0b08a1f3 Mon Sep 17 00:00:00 2001 From: mochi-yu Date: Tue, 5 Sep 2023 01:40:20 +0900 Subject: [PATCH 6/8] =?UTF-8?q?feat:=20`config`=E3=82=B3=E3=83=9E=E3=83=B3?= =?UTF-8?q?=E3=83=89=E3=82=92=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/config.go | 203 ++++++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 5 +- go.sum | 6 ++ 3 files changed, 212 insertions(+), 2 deletions(-) create mode 100644 cmd/config.go diff --git a/cmd/config.go b/cmd/config.go new file mode 100644 index 0000000..6da51ad --- /dev/null +++ b/cmd/config.go @@ -0,0 +1,203 @@ +package cmd + +import ( + "fmt" + "strings" + + "github.com/charmbracelet/bubbles/textinput" + tea "github.com/charmbracelet/bubbletea" + "github.com/cocoide/commitify/util" + "github.com/fatih/color" + "github.com/spf13/cobra" +) + +var ( + configKey = [...]string{"api-key", "language", "format"} + configOption = [][]string{ + {}, + {"Japanese", "English"}, + {"Format 1", "Format 2"}, + } +) + +type configModel struct { + configKeyIndex int + configOptionIndex int + configKeySelected bool + err error + textInput textinput.Model +} + +func initConfigModel() configModel { + ti := textinput.New() + ti.Focus() + + return configModel{ + textInput: ti, + err: nil, + } +} + +func (cm configModel) Init() tea.Cmd { + return textinput.Blink +} + +func (cm configModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { + switch cm.configKeySelected { + // 設定項目を選択する + case false: + switch msg := msg.(type) { + case tea.KeyMsg: + switch msg.Type { + case tea.KeyUp: + if cm.configKeyIndex > 0 { + cm.configKeyIndex-- + } + case tea.KeyDown: + if cm.configKeyIndex < len(configKey)-1 { + cm.configKeyIndex++ + } + case tea.KeyEnter: + cm.configKeySelected = true + return cm, nil + case tea.KeyCtrlC, tea.KeyEsc: + return cm, tea.Quit + } + } + + // 設定項目に値をセットする + case true: + switch len(configOption[cm.configKeyIndex]) { + // 選択肢のない項目は入力を受け付ける + case 0: + var cmd tea.Cmd + switch msg := msg.(type) { + case tea.KeyMsg: + switch msg.Type { + case tea.KeyEnter: + saveConfig(cm) + return cm, tea.Quit + case tea.KeyCtrlC, tea.KeyEsc: + return cm, tea.Quit + } + case error: + cm.err = msg + return cm, nil + } + + cm.textInput, cmd = cm.textInput.Update(msg) + return cm, cmd + + // 選択肢がある場合はセレクターで表示する + default: + switch msg := msg.(type) { + case tea.KeyMsg: + switch msg.Type { + case tea.KeyUp: + if cm.configOptionIndex > 0 { + cm.configOptionIndex-- + } + case tea.KeyDown: + if cm.configOptionIndex < len(configOption[cm.configKeyIndex])-1 { + cm.configOptionIndex++ + } + case tea.KeyEnter: + saveConfig(cm) + return cm, tea.Quit + case tea.KeyCtrlC, tea.KeyEsc: + return cm, tea.Quit + } + } + } + } + + return cm, nil +} + +func (cm configModel) View() string { + var b strings.Builder + + switch cm.configKeySelected { + // 設定項目を選んでいない時 + case false: + white := color.New(color.FgWhite).SprintFunc() + b.WriteString(white("設定項目を選んでください:\n")) + b.WriteString(white(" ↑↓の矢印キーで項目を移動、Enterで選択\n")) + + for i, choice := range configKey { + cyan := color.New(color.FgCyan).SprintFunc() + hiCyan := color.New(color.FgHiCyan).SprintFunc() + if i == cm.configKeyIndex { + b.WriteString(fmt.Sprintf(hiCyan("➡️ %s\n"), choice)) + } else { + b.WriteString(fmt.Sprintf(cyan(" %s\n"), choice)) + } + } + + // 設定項目に値をセットする + case true: + // 選択肢のない項目はテキストエリアを表示 + switch len(configOption[cm.configKeyIndex]) { + case 0: + white := color.New(color.FgWhite).SprintFunc() + b.WriteString(white(fmt.Sprintf( + "ここに%sを入力: %s\n", + configKey[cm.configKeyIndex], + cm.textInput.View(), + ))) + b.WriteString(white(" Enterキーで確定")) + + default: + white := color.New(color.FgWhite).SprintFunc() + b.WriteString(white("設定内容を選んでください:\n")) + b.WriteString(white(" ↑↓の矢印キーで項目を移動、Enterで選択\n")) + + for i, option := range configOption[cm.configKeyIndex] { + cyan := color.New(color.FgCyan).SprintFunc() + hiCyan := color.New(color.FgHiCyan).SprintFunc() + if i == cm.configOptionIndex { + b.WriteString(fmt.Sprintf(hiCyan("➡️ %s\n"), option)) + } else { + b.WriteString(fmt.Sprintf(cyan(" %s\n"), option)) + } + } + } + } + + return b.String() +} + +var configCmd = &cobra.Command{ + Use: "config", + Short: "設定を変更します", + Long: `設定を変更します。設定項目はコマンドを実行すると表示されます。`, + Run: func(cmd *cobra.Command, args []string) { + p := tea.NewProgram(initConfigModel()) + p.Run() + }, +} + +func init() { + rootCmd.AddCommand(configCmd) +} + +func saveConfig(cm configModel) { + currentConfig, err := util.ReadConfig() + if err != nil { + fmt.Println(err) + } + + switch cm.configKeyIndex { + case 0: + currentConfig.ChatGptApiKey = cm.textInput.Value() + case 1: + currentConfig.UseLanguage = configOption[cm.configKeyIndex][cm.configOptionIndex] + case 2: + currentConfig.CommitFormat = configOption[cm.configKeyIndex][cm.configOptionIndex] + } + + err = util.WriteConfig(currentConfig) + if err != nil { + fmt.Println(err) + } +} diff --git a/go.mod b/go.mod index 5c207dc..824f8f7 100644 --- a/go.mod +++ b/go.mod @@ -29,9 +29,11 @@ require ( ) require ( + github.com/atotto/clipboard v0.1.4 // indirect github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect + github.com/charmbracelet/bubbles v0.16.1 // indirect + github.com/charmbracelet/lipgloss v0.7.1 // indirect github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect - github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/mattn/go-isatty v0.0.18 // indirect github.com/mattn/go-localereader v0.0.1 // indirect @@ -41,7 +43,6 @@ require ( github.com/muesli/reflow v0.3.0 // indirect github.com/muesli/termenv v0.15.1 // indirect github.com/rivo/uniseg v0.2.0 // indirect - github.com/spf13/pflag v1.0.5 // indirect golang.org/x/sync v0.1.0 // indirect golang.org/x/sys v0.8.0 // indirect golang.org/x/term v0.6.0 // indirect diff --git a/go.sum b/go.sum index 8ad886b..274f97b 100644 --- a/go.sum +++ b/go.sum @@ -38,11 +38,17 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= +github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/charmbracelet/bubbles v0.16.1 h1:6uzpAAaT9ZqKssntbvZMlksWHruQLNxg49H5WdeuYSY= +github.com/charmbracelet/bubbles v0.16.1/go.mod h1:2QCp9LFlEsBQMvIYERr7Ww2H2bA7xen1idUDIzm/+Xc= github.com/charmbracelet/bubbletea v0.24.2 h1:uaQIKx9Ai6Gdh5zpTbGiWpytMU+CfsPp06RaW2cx/SY= github.com/charmbracelet/bubbletea v0.24.2/go.mod h1:XdrNrV4J8GiyshTtx3DNuYkR1FDaJmO3l2nejekbsgg= +github.com/charmbracelet/lipgloss v0.7.1 h1:17WMwi7N1b1rVWOjMT+rCh7sQkvDU75B2hbZpc5Kc1E= +github.com/charmbracelet/lipgloss v0.7.1/go.mod h1:yG0k3giv8Qj8edTCbbg6AlQ5e8KNWpFujkNawKNhE2c= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= From 5c02115f963d76355def35e4825a9997540d377c Mon Sep 17 00:00:00 2001 From: mochi-yu Date: Tue, 5 Sep 2023 01:40:43 +0900 Subject: [PATCH 7/8] =?UTF-8?q?fix:=20setting=E3=82=B3=E3=83=9E=E3=83=B3?= =?UTF-8?q?=E3=83=89=E3=82=92revert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/settings.go | 44 -------------------------------------------- 1 file changed, 44 deletions(-) delete mode 100644 cmd/settings.go diff --git a/cmd/settings.go b/cmd/settings.go deleted file mode 100644 index d953b43..0000000 --- a/cmd/settings.go +++ /dev/null @@ -1,44 +0,0 @@ -package cmd - -import ( - "fmt" - "log" - - "github.com/cocoide/commitify/util" - "github.com/spf13/cobra" -) - -var setAPIKeyCmd = &cobra.Command{ - Use: "set-apikey [api_key]", - Short: "API Key settings for ChatGPT", - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - config, _ := util.ReadConfig() - config.ChatGptApiKey = args[0] - if err := util.WriteConfig(config); err != nil { - log.Fatal("Failed to write into config", err) - } - fmt.Println("ChatGPT Token has been set") - }, -} - -var showAPIKeyCmd = &cobra.Command{ - Use: "show-apikey", - Short: "Display ChatGPT API key", - Run: func(cmd *cobra.Command, args []string) { - config, err := util.ReadConfig() - if err != nil { - log.Fatal("Failed to read config:", err) - } - if config.ChatGptApiKey == "" { - fmt.Println("API key is not set") - } else { - fmt.Println("ChatGPT APIKey:", config.ChatGptApiKey) - } - }, -} - -func init() { - rootCmd.AddCommand(setAPIKeyCmd) - rootCmd.AddCommand(showAPIKeyCmd) -} From 354b9e84d12e3db2f4dc32d616a9065bb2da6ea2 Mon Sep 17 00:00:00 2001 From: mochi-yu Date: Tue, 5 Sep 2023 02:27:10 +0900 Subject: [PATCH 8/8] =?UTF-8?q?fix:=20=E8=A8=AD=E5=AE=9A=E3=83=95=E3=82=A1?= =?UTF-8?q?=E3=82=A4=E3=83=AB=E3=81=8C=E3=81=82=E3=82=8B=E3=81=8B=E3=81=A9?= =?UTF-8?q?=E3=81=86=E3=81=8B=E3=81=AE=E7=A2=BA=E8=AA=8D=E3=82=92=E3=80=81?= =?UTF-8?q?=E8=B5=B7=E5=8B=95=E6=99=82=E3=81=AB=E8=A1=8C=E3=81=86=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 11 +++++++++++ util/config.go | 17 ----------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/main.go b/main.go index 829c11e..fbd7bac 100644 --- a/main.go +++ b/main.go @@ -1,9 +1,20 @@ package main import ( + "fmt" + "os" + "github.com/cocoide/commitify/cmd" ) func main() { + // configファイルがあるかどうかを確認 + _, err := os.Stat("config.yaml") + if os.IsNotExist(err) { + if _, err := os.Create("config.yaml"); err != nil { + fmt.Printf("error creating config file, %s", err.Error()) + } + } + cmd.Execute() } diff --git a/util/config.go b/util/config.go index 6342ac3..ba9e8ca 100644 --- a/util/config.go +++ b/util/config.go @@ -3,7 +3,6 @@ package util import ( "encoding/json" "fmt" - "os" "github.com/cocoide/commitify/internal/entity" "github.com/spf13/viper" @@ -12,14 +11,6 @@ import ( func ReadConfig() (*entity.Config, error) { var result entity.Config - // configファイルがあるかどうかを確認 - _, err := os.Stat("config.yaml") - if os.IsNotExist(err) { - if _, err := os.Create("config.yaml"); err != nil { - return &result, fmt.Errorf("error creating config file, %s", err.Error()) - } - } - viper.AddConfigPath(".") viper.SetConfigName("config") viper.SetConfigType("yaml") @@ -33,14 +24,6 @@ func ReadConfig() (*entity.Config, error) { } func WriteConfig(config *entity.Config) error { - // configファイルがあるかどうかを確認 - _, err := os.Stat("config.yaml") - if !os.IsNotExist(err) { - if _, err := os.Create("config.yaml"); err != nil { - return fmt.Errorf("error creating config file, %s", err.Error()) - } - } - viper.AddConfigPath(".") viper.SetConfigName("config") viper.SetConfigType("yaml")