MCPcopy
hub / github.com/cheat/cheat / Run

Function Run

internal/installer/run.go:12–52  ·  view source on GitHub ↗

Run runs the installer

(configs string, confpath string)

Source from the content-addressed store, hash-verified

10
11// Run runs the installer
12func 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}

Callers 4

runFunction · 0.92
TestRunFunction · 0.85
TestRunPromptErrorFunction · 0.85

Calls 6

CloneFunction · 0.92
InitFunction · 0.92
ExpandTemplateFunction · 0.85
cheatsheetDirsFunction · 0.85
PromptFunction · 0.85
CommentCommunityFunction · 0.85

Tested by 3

TestRunFunction · 0.68
TestRunPromptErrorFunction · 0.68