mirror of
https://github.com/cheat/cheat.git
synced 2026-03-07 11:13:33 +01:00
- Remove unused parameters, dead files, and inaccurate doc.go files - Extract shared helpers, eliminate duplication - Rename cheatpath.Cheatpath to cheatpath.Path - Optimize filesystem walks (WalkDir, skip .git) - Move sheet name validation to sheet.Validate - Move integration tests to test/integration/ - Consolidate internal/mock into mocks/ - Move fuzz.sh to test/ - Inline loadSheets helper into command callers - Extract config.New into its own file - Fix stale references in HACKING.md and CLAUDE.md - Restore plan9 build target - Remove redundant and low-value tests - Clean up project documentation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package installer
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/cheat/cheat/internal/config"
|
|
"github.com/cheat/cheat/internal/repo"
|
|
)
|
|
|
|
// Run runs the installer
|
|
func Run(configs string, confpath string) error {
|
|
|
|
// expand template placeholders with platform-appropriate paths
|
|
configs = ExpandTemplate(configs, confpath)
|
|
|
|
// determine cheatsheet directory paths
|
|
community, personal, work := cheatsheetDirs(confpath)
|
|
|
|
// prompt the user to download the community cheatsheets
|
|
yes, err := Prompt(
|
|
"Would you like to download the community cheatsheets? [Y/n]",
|
|
true,
|
|
)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to prompt: %v", err)
|
|
}
|
|
|
|
// clone the community cheatsheets if so instructed
|
|
if yes {
|
|
fmt.Printf("Cloning community cheatsheets to %s.\n", community)
|
|
if err := repo.Clone(community); err != nil {
|
|
return fmt.Errorf("failed to clone cheatsheets: %v", err)
|
|
}
|
|
} else {
|
|
configs = CommentCommunity(configs, confpath)
|
|
}
|
|
|
|
// always create personal and work directories
|
|
for _, dir := range []string{personal, work} {
|
|
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
|
|
return fmt.Errorf("failed to create directory: %v", err)
|
|
}
|
|
}
|
|
|
|
// the config file does not exist, so we'll try to create one
|
|
if err = config.Init(confpath, configs); err != nil {
|
|
return fmt.Errorf("failed to create config file: %v", err)
|
|
}
|
|
|
|
return nil
|
|
}
|