MCPcopy Create free account
hub / github.com/52funny/pikpakcli / Run

Function Run

cli/setup/setup.go:66–105  ·  view source on GitHub ↗
(opts Options)

Source from the content-addressed store, hash-verified

64}
65
66func Run(opts Options) (string, error) {
67 if opts.Prompts == nil {
68 opts.Prompts = terminalPrompts{}
69 }
70
71 targetPath := opts.TargetPath
72 if targetPath == "" {
73 var err error
74 targetPath, err = conf.DefaultConfigPath()
75 if err != nil {
76 return "", fmt.Errorf("get default config path: %w", err)
77 }
78 }
79
80 if !opts.Force {
81 if _, err := os.Stat(targetPath); err == nil {
82 return "", fmt.Errorf("config already exists: %s (use --force to overwrite)", targetPath)
83 } else if !errors.Is(err, os.ErrNotExist) {
84 return "", fmt.Errorf("check config path: %w", err)
85 }
86 }
87
88 values, err := collectValues(opts.Prompts)
89 if err != nil {
90 return "", err
91 }
92
93 bs, err := buildConfig(values)
94 if err != nil {
95 return "", err
96 }
97
98 if err := os.MkdirAll(filepath.Dir(targetPath), 0700); err != nil {
99 return "", fmt.Errorf("create config dir: %w", err)
100 }
101 if err := os.WriteFile(targetPath, bs, 0600); err != nil {
102 return "", fmt.Errorf("write config file: %w", err)
103 }
104 return targetPath, nil
105}
106
107func collectValues(prompts Prompts) (setupValues, error) {
108 username, err := prompts.ReadLine("PikPak username: ")

Calls 3

DefaultConfigPathFunction · 0.92
collectValuesFunction · 0.85
buildConfigFunction · 0.85