Skip to content

Commit

Permalink
fix: perform login checks and closes issue #20 (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelramos authored Aug 8, 2022
1 parent 2556b91 commit 40755e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions core/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ func (ctx *App) InitAuthor() error {

func (ctx *App) UpdateAuthorMetadata(author *models.AuthorFileProps) error {
config := GetConfig()
rcFile := filepath.Join(config.HomeDir, ".sublime/rc.json")
_, err := os.ReadFile(rcFile)
if err != nil {

sublimeDir := filepath.Join(config.HomeDir, ".sublime")
rcFile := filepath.Join(sublimeDir, "rc.json")
if _, err := os.Stat(rcFile); os.IsNotExist(err) {
utils.WarningOut(utils.MessageErrorAuthorFileMissing)
}

Expand All @@ -81,7 +82,13 @@ func (ctx *App) UpdateAuthorMetadata(author *models.AuthorFileProps) error {
return errors.New(utils.MessageErrorIndentFile)
}

err = os.WriteFile(filepath.Join(config.HomeDir, ".sublime/rc.json"), data, 0644)
if _, err := os.Stat(sublimeDir); os.IsNotExist(err) {
if err := os.Mkdir(sublimeDir, 0755); err != nil {
return errors.New(utils.MessageErrorCommandRegisterHomeDir)
}
}

err = os.WriteFile(rcFile, data, 0644)
if err != nil {
return errors.New(utils.MessageErrorWriteFile)
}
Expand Down
2 changes: 1 addition & 1 deletion utils/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const (
MessageCommandRootShort string = "CLI tool to manage monorepo packages."
MessageCommandRootTokenExpire string = "Your token is expired. Start renew action."

MessageErrorAuthorFileMissing string = "Author file not found. Please register first then login to cloud service."
MessageErrorAuthorFileMissing string = "Author file not found. Please register first or login to cloud service."
MessageErrorParseFile string = "Unable to parse file."
MessageErrorIndentFile string = "Unable to indent file."
MessageErrorWriteFile string = "Unable to write file"
Expand Down

0 comments on commit 40755e1

Please sign in to comment.