mirror of https://github.com/cheat/cheat.git
feat(installer): default path selection
Modify the installer to improve default config and cheatsheet path selection.
This commit is contained in:
parent
e15bc6c966
commit
a08dca70d9
|
@ -10,7 +10,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/docopt/docopt-go"
|
"github.com/docopt/docopt-go"
|
||||||
"github.com/mitchellh/go-homedir"
|
|
||||||
|
|
||||||
"github.com/cheat/cheat/internal/cheatpath"
|
"github.com/cheat/cheat/internal/cheatpath"
|
||||||
"github.com/cheat/cheat/internal/config"
|
"github.com/cheat/cheat/internal/config"
|
||||||
|
@ -68,6 +67,11 @@ func main() {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// determine the correct paths for the config file and (optional) community
|
||||||
|
// cheatsheet download
|
||||||
|
confpath = confpaths[0]
|
||||||
|
confdir := path.Dir(confpath)
|
||||||
|
|
||||||
// prompt the user to download the community cheatsheets
|
// prompt the user to download the community cheatsheets
|
||||||
yes, err = installer.Prompt(
|
yes, err = installer.Prompt(
|
||||||
"Would you like to download the community cheatsheets? [Y/n]",
|
"Would you like to download the community cheatsheets? [Y/n]",
|
||||||
|
@ -81,26 +85,15 @@ func main() {
|
||||||
// clone the community cheatsheets if so instructed
|
// clone the community cheatsheets if so instructed
|
||||||
if yes {
|
if yes {
|
||||||
|
|
||||||
// get the user's home directory
|
|
||||||
home, err := homedir.Dir()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(
|
|
||||||
os.Stderr,
|
|
||||||
"failed to create config: failed to get user home directory: %v\n",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// clone the community cheatsheets
|
// clone the community cheatsheets
|
||||||
community := path.Join(home, ".config/cheat/cheatsheets/community")
|
community := path.Join(confdir, "/cheatsheets/community")
|
||||||
if err := installer.Clone(community); err != nil {
|
if err := installer.Clone(community); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "failed to create config: %v\n", err)
|
fmt.Fprintf(os.Stderr, "failed to create config: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a directory for personal cheatsheets too
|
// create a directory for personal cheatsheets too
|
||||||
personal := path.Join(home, ".config/cheat/cheatsheets/personal")
|
personal := path.Join(confdir, "/cheatsheets/personal")
|
||||||
if err := os.MkdirAll(personal, os.ModePerm); err != nil {
|
if err := os.MkdirAll(personal, os.ModePerm); err != nil {
|
||||||
fmt.Fprintf(
|
fmt.Fprintf(
|
||||||
os.Stderr,
|
os.Stderr,
|
||||||
|
@ -112,20 +105,18 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// the config file does not exist, so we'll try to create one
|
// the config file does not exist, so we'll try to create one
|
||||||
if err = config.Init(confpaths[0], configs()); err != nil {
|
if err = config.Init(confpath, configs()); err != nil {
|
||||||
fmt.Fprintf(
|
fmt.Fprintf(
|
||||||
os.Stderr,
|
os.Stderr,
|
||||||
"failed to create config file: %s: %v\n",
|
"failed to create config file: %s: %v\n",
|
||||||
confpaths[0],
|
confpath,
|
||||||
err,
|
err,
|
||||||
)
|
)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
confpath = confpaths[0]
|
|
||||||
|
|
||||||
fmt.Printf("Created config file: %s\n", confpath)
|
fmt.Printf("Created config file: %s\n", confpath)
|
||||||
fmt.Println("Please edit this file now to configure cheat.")
|
fmt.Println("Please read this file for advanced configuration information.")
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue