Run runs the installer
(configs string, confpath string)
| 10 | |
| 11 | // Run runs the installer |
| 12 | func Run(configs string, confpath string) error { |
| 13 | |
| 14 | // expand template placeholders with platform-appropriate paths |
| 15 | configs = ExpandTemplate(configs, confpath) |
| 16 | |
| 17 | // determine cheatsheet directory paths |
| 18 | community, personal, work := cheatsheetDirs(confpath) |
| 19 | |
| 20 | // prompt the user to download the community cheatsheets |
| 21 | yes, err := Prompt( |
| 22 | "Would you like to download the community cheatsheets? [Y/n]", |
| 23 | true, |
| 24 | ) |
| 25 | if err != nil { |
| 26 | return fmt.Errorf("failed to prompt: %v", err) |
| 27 | } |
| 28 | |
| 29 | // clone the community cheatsheets if so instructed |
| 30 | if yes { |
| 31 | fmt.Printf("Cloning community cheatsheets to %s.\n", community) |
| 32 | if err := repo.Clone(community); err != nil { |
| 33 | return fmt.Errorf("failed to clone cheatsheets: %v", err) |
| 34 | } |
| 35 | } else { |
| 36 | configs = CommentCommunity(configs, confpath) |
| 37 | } |
| 38 | |
| 39 | // always create personal and work directories |
| 40 | for _, dir := range []string{personal, work} { |
| 41 | if err := os.MkdirAll(dir, os.ModePerm); err != nil { |
| 42 | return fmt.Errorf("failed to create directory: %v", err) |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | // the config file does not exist, so we'll try to create one |
| 47 | if err = config.Init(confpath, configs); err != nil { |
| 48 | return fmt.Errorf("failed to create config file: %v", err) |
| 49 | } |
| 50 | |
| 51 | return nil |
| 52 | } |