-
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
1e65df0
commit 3667602
Showing
2 changed files
with
90 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/se7entyse7en/pydockenv/internal/environment" | ||
"github.com/se7entyse7en/pydockenv/log" | ||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var removeCmd = &cobra.Command{ | ||
Use: "remove [environment-name]", | ||
Short: "Remove a virtual environment", | ||
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 := parseRemoveArgs(cmd, args) | ||
if err != nil { | ||
logger.WithError(err).Fatal("Cannot parse arguments") | ||
} | ||
|
||
ctxLogger := logger.WithFields(logrus.Fields{ | ||
"name": cmdArgs.Name, | ||
}) | ||
ctxLogger.Info("Removing virtual environment...") | ||
|
||
if err := environment.Remove(cmdArgs.Name); err != nil { | ||
logger.WithError(err).Fatal("Cannot remove virtual environment") | ||
} | ||
|
||
ctxLogger.Info("Virtual environment removed!") | ||
}, | ||
} | ||
|
||
func parseRemoveArgs(cmd *cobra.Command, args []string) (*removeArgs, error) { | ||
name := args[0] | ||
return &removeArgs{Name: name}, nil | ||
} | ||
|
||
type removeArgs struct { | ||
Name string | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(removeCmd) | ||
} |
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