Skip to content

feat: add dotfiles command #1723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 32 commits into from
May 25, 2022
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
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
fixup
  • Loading branch information
f0ssel committed May 25, 2022
commit 0467613f4c92ebdf1a2c85956df8a65b2cc7a9d0
9 changes: 5 additions & 4 deletions cli/dotfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ func dotfiles() *cobra.Command {
moved := false
if dotfilesExists {
du, err := cfg.DotfilesURL().Read()
if err != nil {
if err != nil && !errors.Is(err, os.ErrNotExist) {
return xerrors.Errorf("reading dotfiles url config: %w", err)
}
// if the git url has changed we create a backup and clone fresh
if gitRepo != du {
backupDir := fmt.Sprintf("%s_backup_%s", dotfilesDir, time.Now().Format(time.RFC3339))
_, err = cliui.Prompt(cmd, cliui.PromptOptions{
Text: fmt.Sprintf("The dotfiles URL has changed from %s to %s. Coder will backup the existing repo to %s.\n\n Continue?", du, gitRepo, backupDir),
Text: fmt.Sprintf("The dotfiles URL has changed from \"%s\" to \"%s\".\n Coder will backup the existing repo to %s.\n\n Continue?", du, gitRepo, backupDir),
IsConfirm: true,
})
if err != nil {
Expand All @@ -74,6 +74,7 @@ func dotfiles() *cobra.Command {
if err != nil {
return xerrors.Errorf("renaming dir %s: %w", dotfilesDir, err)
}
_, _ = fmt.Fprint(cmd.OutOrStdout(), "Done backup up dotfiles.\n")
dotfilesExists = false
moved = true
}
Expand All @@ -95,7 +96,7 @@ func dotfiles() *cobra.Command {
}
gitCmdDir = cfgDir
subcommands = []string{"clone", args[0], dotfilesRepoDir}
promptText = fmt.Sprintf("Cloning %s into directory %s.\n Continue?", gitRepo, dotfilesDir)
promptText = fmt.Sprintf("Cloning %s into directory %s.\n\n Continue?", gitRepo, dotfilesDir)
}

_, err = cliui.Prompt(cmd, cliui.PromptOptions{
Expand All @@ -106,7 +107,7 @@ func dotfiles() *cobra.Command {
return err
}

// ensure config dir exists
// ensure command dir exists
err = os.MkdirAll(gitCmdDir, 0750)
if err != nil {
return xerrors.Errorf("ensuring dir at %s: %w", gitCmdDir, err)
Expand Down