Skip to content
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

Add “doctor” chezmoi command #137

Closed
wants to merge 8 commits into from
Closed

Add “doctor” chezmoi command #137

wants to merge 8 commits into from

Conversation

kkirsche
Copy link
Contributor

@kkirsche kkirsche commented Jan 17, 2019

Add a chezmoi doctor command. Not sure the best way to test this though (unit test wise). Thoughts?

 ~/git/go/src/github.com/twpayne/chezmoi >> feature/cmd_doctor ? $ go build -o cmoi                                 ✔
 ~/git/go/src/github.com/twpayne/chezmoi >> feature/cmd_doctor ? $ ./cmoi doctor
Arch: amd64
OS: darwin
Configuration File: Exists (-rw-r--r-- /Users/kkirsche/.config/chezmoi/chezmoi.yaml)
Destination Directory: Exists (-rwxr-xr-x /Users/kkirsche)
Source Directory: Exists (-rwx------ /Users/kkirsche/.local/share/chezmoi)
Hashicorp Vault: Installed (-r-xr-xr-x /Users/kkirsche/.local/share/chezmoi)
Bitwarden: Not Found
LastPass: Not Found

@kkirsche
Copy link
Contributor Author

This PR is related to the doctor command mentioned in #134

@kkirsche
Copy link
Contributor Author

Oops, I had an error in the paths being printed. Fixed in d585022:

 ~/git/go/src/github.com/twpayne/chezmoi >> feature/cmd_doctor ? $ ./cmoi doctor
Arch: amd64
OS: darwin
Configuration File: Exists (-rw-r--r-- /Users/kkirsche/.config/chezmoi/chezmoi.yaml)
Destination Directory: Exists (-rwxr-xr-x /Users/kkirsche)
Source Directory: Exists (-rwx------ /Users/kkirsche/.local/share/chezmoi)
Hashicorp Vault: Installed (-r-xr-xr-x /usr/local/bin/vault)
Bitwarden: Not Found
LastPass: Not Found

cmd/doctor.go Outdated Show resolved Hide resolved
cmd/doctor.go Show resolved Hide resolved
cmd/doctor.go Outdated Show resolved Hide resolved
@kkirsche
Copy link
Contributor Author

If you prefer aligned, we can use a tabwriter (https://golang.org/pkg/text/tabwriter/) to align it like so:

Arch:                    amd64
OS:                      darwin
Configuration File:      Exists      (-rw-r--r-- /Users/kkirsche/.config/chezmoi/chezmoi.yaml)
Destination Directory:   Exists      (-rwxr-xr-x /Users/kkirsche)
Source Directory:        Exists      (-rwx------ /Users/kkirsche/.local/share/chezmoi)
Hashicorp Vault:         Installed   (-r-xr-xr-x /usr/local/bin/vault)
Bitwarden:               Not Found
LastPass:                Not Found

@twpayne
Copy link
Owner

twpayne commented Jan 17, 2019

#138 is also relevant now :)

@kkirsche
Copy link
Contributor Author

Output:

 ~/git/go/src/github.com/twpayne/chezmoi >> feature/cmd_doctor ? $ ./cmoi doctor
Arch:                    amd64
OS:                      darwin
Configuration File:      Exists   (-rw-r--r-- /Users/kkirsche/.config/chezmoi/chezmoi.yaml)
Destination Directory:   Exists   (-rwxr-xr-x /Users/kkirsche)
Source Directory:        Exists   (-rwx------ /Users/kkirsche/.local/share/chezmoi)
Bitwarden:               Not Found
LastPass:                Not Found
Vault:                   Installed   (-r-xr-xr-x /usr/local/bin/vault)

@twpayne
Copy link
Owner

twpayne commented Jan 17, 2019

For the output, let's focus on the logic first and then make the UX pretty second :)

cmd/doctor.go Show resolved Hide resolved
cmd/doctor.go Outdated Show resolved Hide resolved
cmd/doctor.go Outdated Show resolved Hide resolved
cmd/doctor.go Show resolved Hide resolved
@kkirsche
Copy link
Contributor Author

Updated output:

 ~/git/go/src/github.com/twpayne/chezmoi >> feature/cmd_doctor ? $ go build -o cmoi
 ~/git/go/src/github.com/twpayne/chezmoi >> feature/cmd_doctor ? $ ./cmoi doctor
Arch:                    amd64
OS:                      darwin
Configuration File:      Exists   (-rw-r--r-- /Users/kkirsche/.config/chezmoi/chezmoi.yaml)
Destination Directory:   Exists   (-rwxr-xr-x /Users/kkirsche)
Source Directory:        Exists   (-rwx------ /Users/kkirsche/.local/share/chezmoi)
Bitwarden:               Not Found
LastPass:                Not Found
Pass:                    Not Found
Vault:                   Installed   (-r-xr-xr-x /usr/local/bin/vault)

@twpayne
Copy link
Owner

twpayne commented Jan 17, 2019

Another thing to add: please return nil if everything is ok, and call os.Exit(1) if it is not. This will allow chezmoi doctor to be used in scripts.

@kkirsche
Copy link
Contributor Author

What situations do you define as "not ok"?

@twpayne
Copy link
Owner

twpayne commented Jan 17, 2019

What situations do you define as "not ok"?

Good question! I would say anything that prevents chezmoi from running at all, e.g. missing source or destination directories. Missing config files is OK, and missing password manager binaries is OK.

@kkirsche
Copy link
Contributor Author

Added exit codes 👍

@kkirsche
Copy link
Contributor Author

kkirsche commented Jan 17, 2019

Updated output:

 ~/git/go/src/github.com/twpayne/chezmoi >> feature/cmd_doctor $ go build -o cmoi
 ~/git/go/src/github.com/twpayne/chezmoi >> feature/cmd_doctor $ ./cmoi doctor
Arch:                    amd64
OS:                      darwin
Configuration File:      Exists      (-rw-r--r-- /Users/kkirsche/.config/chezmoi/chezmoi.yaml)
Destination Directory:   Exists      (-rwxr-xr-x /Users/kkirsche)
Source Directory:        Exists      (-rwx------ /Users/kkirsche/.local/share/chezmoi)
Bitwarden:               Not Found   (looking for: bw)
Editor:                  Installed   (-r-xr-xr-x /usr/local/bin/nvim)
LastPass:                Not Found   (looking for: lpass)
Pass:                    Not Found   (looking for: pass)
Vault:                   Installed   (-r-xr-xr-x /usr/local/bin/vault)
VCS:                     Installed   (-rwxr-xr-x /usr/local/bin/git)
 ~/git/go/src/github.com/twpayne/chezmoi >> feature/cmd_doctor $ echo $?
0

EDIT: Updated to show the editor component

twpayne
twpayne previously approved these changes Jan 17, 2019
@twpayne twpayne dismissed their stale review January 17, 2019 15:46

Commits need squashing before merging

@twpayne
Copy link
Owner

twpayne commented Jan 17, 2019

Thanks for addressing the commands. Please can you squash the commits in to a single one with the message "Add doctor command" and I will then merge.

@kkirsche
Copy link
Contributor Author

Well, squashing stuff broke the PR 😢

@kkirsche kkirsche closed this Jan 17, 2019
@kkirsche kkirsche mentioned this pull request Jan 17, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants