Skip to content

Commit

Permalink
Support LEETGO_WORKDIR
Browse files Browse the repository at this point in the history
  • Loading branch information
j178 committed Jan 30, 2023
1 parent 5706be4 commit 7bc13af
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ leetgo.exe
leetgo.yaml
completions/
dist/
/go/
/contest/
/out
5 changes: 3 additions & 2 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ var configCmd = &cobra.Command{
Short: "Show configurations",
Run: func(cmd *cobra.Command, args []string) {
cfg := config.Get()
cmd.Println("Global config dir:", cfg.ConfigDir())
cmd.Println("Global config file:", cfg.GlobalConfigFile())
cmd.Println("Global config dir :", cfg.ConfigDir())
cmd.Println("Global config file :", cfg.GlobalConfigFile())
cmd.Println("Project root :", cfg.ProjectRoot())
cmd.Println("Project config file:", cfg.ProjectConfigFile())
cmd.Println("Full configurations:")
cmd.Println()
Expand Down
2 changes: 1 addition & 1 deletion cmd/contest.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,6 @@ var unregisterCmd = &cobra.Command{
}

func init() {
contestCmd.Flags().BoolVarP(&openInBrowser, "browser", "b", false, "do not open in browser")
contestCmd.Flags().BoolVarP(&openInBrowser, "browser", "b", false, "open question page in browser")
contestCmd.AddCommand(unregisterCmd)
}
11 changes: 11 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ var rootCmd = &cobra.Command{
SilenceErrors: true,
SilenceUsage: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
err := initWorkDir()
if err != nil {
return err
}
initLogger()
return config.Load(cmd == initCmd)
},
Expand All @@ -62,6 +66,13 @@ func UsageString() string {
return rootCmd.UsageString()
}

func initWorkDir() error {
if os.Getenv("LEETGO_WORKDIR") != "" {
return os.Chdir(os.Getenv("LEETGO_WORKDIR"))
}
return nil
}

func initLogger() {
opts := &hclog.LoggerOptions{
Level: hclog.Info,
Expand Down

0 comments on commit 7bc13af

Please sign in to comment.