-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Lou Marvin Caraig <[email protected]>
- Loading branch information
1 parent
b342ff6
commit ea7c73e
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/se7entyse7en/pydockenv/internal/dependency" | ||
"github.com/se7entyse7en/pydockenv/log" | ||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var uninstallCmd = &cobra.Command{ | ||
Use: "uninstall [package_1] [package_2] ... [package_n]", | ||
Short: "unInstall packages from args", | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
logger := log.Logger | ||
err := log.SetupLogger(cmd) | ||
if err != nil { | ||
logger.WithError(err).Fatal("Cannot setup logger") | ||
} | ||
|
||
cmdArgs, err := parseUninstallArgs(cmd, args) | ||
if err != nil { | ||
logger.WithError(err).Fatal("Cannot parse arguments") | ||
} | ||
|
||
ctxLogger := logger.WithFields(logrus.Fields{ | ||
"packages": cmdArgs.Packages, | ||
}) | ||
ctxLogger.Info("Uninstalling packages...") | ||
|
||
if err := dependency.Uninstall(&dependency.Packages{ | ||
RawDependencies: cmdArgs.Packages}, | ||
cmdArgs.Yes, | ||
); err != nil { | ||
logger.WithError(err).Fatal("Cannot uninstall packages") | ||
} | ||
|
||
ctxLogger.Info("Packages uninstalled!") | ||
}, | ||
} | ||
|
||
func parseUninstallArgs(cmd *cobra.Command, args []string) (*uninstallArgs, error) { | ||
yes, err := getBoolArg(cmd, "yes") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &uninstallArgs{Packages: args, Yes: yes}, nil | ||
} | ||
|
||
type uninstallArgs struct { | ||
Packages []string | ||
Yes bool | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(uninstallCmd) | ||
|
||
uninstallCmd.Flags().BoolP("yes", "y", false, "Don't ask for confirmation") | ||
} |