Skip to content

Commit

Permalink
fix: leetgo init flag issue
Browse files Browse the repository at this point in the history
  • Loading branch information
j178 committed Jun 14, 2023
1 parent c8760c0 commit 92f1dd0
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ And `leetgo` also supports real-time generation of **contest questions**, submit
## Quick Start

1. [Install leetgo](#installation)
2. Initialize leetgo: `leetgo init -t <us or cn>`
2. Initialize leetgo: `leetgo init -t <us or cn> -l <lang>`
3. Edit leetgo config file: `leetgo.yaml` and `~/.config/leetgo/config.yaml`
4. Pick a question: `leetgo pick <id or name or today>`
5. Test your code: `leetgo test last -L`
Expand Down
2 changes: 1 addition & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
## 快速开始

1. [安装 leetgo](#安装)
2. 创建一个项目: `leetgo init -t <us or cn>`
2. 创建一个项目: `leetgo init -t <us or cn> -l <lang>`
3. 编辑配置文件: `leetgo.yaml` and `~/.config/leetgo/config.yaml`
4. 选择一个问题: `leetgo pick <id or name or today>`
5. 测试你的代码: `leetgo test last -L`
Expand Down
2 changes: 1 addition & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var initCmd = &cobra.Command{
}

func init() {
initCmd.Flags().StringVarP(&initTemplate, "template", "t", "us", "template to use, cn or us")
initCmd.Flags().StringVarP(&initTemplate, "template", "t", "", "template to use, cn or us")
initCmd.Flags().BoolVarP(&force, "force", "f", false, "overwrite global config file if exists")

_ = initCmd.RegisterFlagCompletionFunc(
Expand Down
4 changes: 3 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,15 @@ func Load(init bool) error {

// load global configuration
cfg := defaultConfig()
viper.SetDefault("code.lang", cfg.Code.Lang)
viper.SetDefault("leetcode.site", cfg.LeetCode.Site)

viper.SetConfigFile(cfg.GlobalConfigFile())
err := viper.ReadInConfig()
if err != nil {
notExist := os.IsNotExist(err)
if init && notExist {
// During `init`, if global config file does not exist, we will create one
// During `init`, if global config file does not exist, we will create one.
err = nil
_ = err
} else {
Expand Down
2 changes: 1 addition & 1 deletion misc/demo.tape
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Type "mkdir my-leetcode-solutions" Enter
Sleep 2
Type "cd my-leetcode-solutions" Enter
Sleep 2
Type "leetgo init -t cn # Init with Chinese template" Enter
Type "leetgo init -t cn -l go" Enter
Sleep 2
Type "# A new leetgo.yaml file is created" Enter
Sleep 2
Expand Down

0 comments on commit 92f1dd0

Please sign in to comment.