Skip to content

Commit

Permalink
refactor(path): Get and use absolute path
Browse files Browse the repository at this point in the history
For the problem that file path is invalid.
  • Loading branch information
5ouma committed Jan 17, 2024
1 parent e655b61 commit 0a7eefc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions cmd/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"path/filepath"

"github.com/spf13/cobra"
)
Expand All @@ -23,14 +24,18 @@ func (cmd *cmd) execLoadCmd(command *cobra.Command, args []string) error {
if err != nil {
return err
}
path, err := filepath.Abs(file)
if err != nil {
return err
}

if err := cmd.loginItems.Load(file); err != nil {
if err := cmd.loginItems.Load(path); err != nil {
return err
}
if err := cmd.loginItems.Add(); err != nil {
return err
}
fmt.Printf("✅ Successfully loaded from \"%s\"!\n", file)
fmt.Printf("✅ Successfully loaded from \"%s\"!\n", path)

return nil
}
9 changes: 7 additions & 2 deletions cmd/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"path/filepath"

"github.com/spf13/cobra"
)
Expand All @@ -24,6 +25,10 @@ func (cmd *cmd) execSaveCmd(command *cobra.Command, args []string) error {
if err != nil {
return err
}
path, err := filepath.Abs(file)
if err != nil {
return err
}
force, err := command.Flags().GetBool("force")
if err != nil {
return err
Expand All @@ -32,10 +37,10 @@ func (cmd *cmd) execSaveCmd(command *cobra.Command, args []string) error {
if err := cmd.loginItems.Get(); err != nil {
return err
}
if err := cmd.loginItems.Save(file, force); err != nil {
if err := cmd.loginItems.Save(path, force); err != nil {
return err
}
fmt.Printf("✅ Successfully saved to \"%s\"!\n", file)
fmt.Printf("✅ Successfully saved to \"%s\"!\n", path)

return nil
}

0 comments on commit 0a7eefc

Please sign in to comment.