Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: added better error handling
  • Loading branch information
BRAVO68WEB committed Jul 19, 2023
commit 3cb96f924819b3c6058b799fff83f57fa41b7a6d
21 changes: 13 additions & 8 deletions cli/dotfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func (r *RootCmd) dotfiles() *clibase.Cmd {
installScriptSet = []string{
"install.sh",
"install",
"bootstrap.sh",
"bootstrap",
// "bootstrap.sh",
// "bootstrap",
"script/bootstrap",
"setup.sh",
"setup",
Expand Down Expand Up @@ -193,16 +193,21 @@ func (r *RootCmd) dotfiles() *clibase.Cmd {
}

_, _ = fmt.Fprintf(inv.Stdout, "Running %s...\n", script)
// it is safe to use a variable command here because it's from
// a filtered list of pre-approved install scripts
// nolint:gosec

// making selected script executable
err = os.Chmod(filepath.Join(dotfilesDir, script), 0o755)
// Check if the script is executable and notify on error
scriptPath := filepath.Join(dotfilesDir, script)
fi, err := os.Stat(scriptPath)
if err != nil {
return xerrors.Errorf("chmod %s: %w", script, err)
return xerrors.Errorf("stat %s: %w", scriptPath, err)
}

if fi.Mode()&0o111 == 0 {
return xerrors.Errorf("%s script is not executable.\nTo solve this :-\n - Clone your dotfiles repo.\n - chmod +x %s\n - git add %s and git commit -m \"Make %s executable\"\n - git push\n", script, script, script, script)
}

// it is safe to use a variable command here because it's from
// a filtered list of pre-approved install scripts
// nolint:gosec
scriptCmd := exec.CommandContext(inv.Context(), filepath.Join(dotfilesDir, script))
scriptCmd.Dir = dotfilesDir
scriptCmd.Stdout = inv.Stdout
Expand Down