Skip to content

Commit

Permalink
Merge pull request #21 from tonedefdev/hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
tonedefdev authored Feb 5, 2023
2 parents 96af447 + f9f34ae commit c530613
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 6 additions & 2 deletions cmd/generate.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"github.com/tonedefdev/terracreds/pkg/helpers"
"github.com/urfave/cli/v2"
)

Expand All @@ -22,8 +23,11 @@ func (cmd *Config) NewCommandGenerate() *cli.Command {
},
},
Action: func(c *cli.Context) error {
GenerateTerraCreds(c, cmd.Version, cmd.Confirm)
return nil
err := GenerateTerraCreds(c, cmd.Version, cmd.Confirm)
if err != nil {
helpers.CheckError(err)
}
return err
},
}

Expand Down
14 changes: 12 additions & 2 deletions cmd/terracreds.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,17 @@ type TerraCreds interface {

// CopyTerraCreds will create a copy of the binary to the destination path.
func CopyTerraCreds(dest string) error {
from, err := os.Open(string(os.Args[0]))
exec, err := os.Executable()
if err != nil {
return err
}

resolvedExecPath, err := filepath.EvalSymlinks(exec)
if err != nil {
return err
}

from, err := os.Open(resolvedExecPath)
if err != nil {
return err
}
Expand All @@ -49,7 +59,7 @@ func CopyTerraCreds(dest string) error {
return err
}

fmt.Fprintf(color.Output, "%s: Copied binary '%s' to '%s'\n", color.CyanString("INFO"), string(os.Args[0]), dest)
fmt.Fprintf(color.Output, "%s: Copied binary '%s' to '%s'\n", color.CyanString("INFO"), resolvedExecPath, dest)
return err
}

Expand Down

0 comments on commit c530613

Please sign in to comment.