MCPcopy Create free account
hub / github.com/compozy/agh / newUninstallCommand

Function newUninstallCommand

internal/cli/lifecycle.go:124–194  ·  view source on GitHub ↗
(deps commandDeps)

Source from the content-addressed store, hash-verified

122}
123
124func newUninstallCommand(deps commandDeps) *cobra.Command {
125 var (
126 purge bool
127 force bool
128 )
129
130 cmd := &cobra.Command{
131 Use: lifecycleUninstallKey,
132 Short: "Stop AGH and remove runtime launch artifacts",
133 Args: cobra.NoArgs,
134 RunE: func(cmd *cobra.Command, _ []string) error {
135 state := detectManagedState(deps)
136 if state.Managed {
137 record := lifecycleRecord{
138 Command: lifecycleUninstallKey,
139 Managed: state.Managed,
140 Manager: state.Manager,
141 Status: lifecycleStatusDeferred,
142 Message: "AGH is managed by an external package manager; no local uninstall changes were made.",
143 Recommendation: managedRecommendation(state.Manager, "uninstall AGH"),
144 }
145 return writeCommandOutput(cmd, lifecycleBundle("Uninstall", record))
146 }
147
148 if purge && !force {
149 return errors.New("cli: --purge requires --force to remove AGH home data")
150 }
151
152 runtime, err := loadRuntimeContext(deps)
153 if err != nil {
154 return err
155 }
156
157 record := lifecycleRecord{
158 Command: lifecycleUninstallKey,
159 HomeDir: runtime.HomePaths.HomeDir,
160 Managed: state.Managed,
161 Manager: state.Manager,
162 }
163
164 stopped, err := stopDaemonForUninstall(cmd.Context(), deps, runtime)
165 if err != nil {
166 return err
167 }
168 record.DaemonStopped = stopped
169
170 removed, err := removeRuntimeArtifacts(runtime.HomePaths)
171 if err != nil {
172 return err
173 }
174 record.Removed = removed
175
176 if purge {
177 if err := os.RemoveAll(runtime.HomePaths.HomeDir); err != nil {
178 return fmt.Errorf("cli: purge AGH home %q: %w", runtime.HomePaths.HomeDir, err)
179 }
180 record.Purged = true
181 }

Callers 1

newRootCommandFunction · 0.85

Calls 7

detectManagedStateFunction · 0.85
managedRecommendationFunction · 0.85
writeCommandOutputFunction · 0.85
lifecycleBundleFunction · 0.85
loadRuntimeContextFunction · 0.85
stopDaemonForUninstallFunction · 0.85
removeRuntimeArtifactsFunction · 0.85

Tested by

no test coverage detected