Skip to content

Commit

Permalink
Add list-packages command
Browse files Browse the repository at this point in the history
Signed-off-by: Lou Marvin Caraig <[email protected]>
  • Loading branch information
se7entyse7en committed Jun 27, 2020
1 parent ea7c73e commit 8852b63
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
31 changes: 31 additions & 0 deletions cmd/list_packages.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package cmd

import (
"github.com/se7entyse7en/pydockenv/internal/dependency"
"github.com/se7entyse7en/pydockenv/log"
"github.com/spf13/cobra"
)

var listPackagesCmd = &cobra.Command{
Use: "list-packages",
Short: "List the packages installed for the current virtual environments",
Run: func(cmd *cobra.Command, args []string) {
logger := log.Logger
err := log.SetupLogger(cmd)
if err != nil {
logger.WithError(err).Fatal("Cannot setup logger")
}

logger.Info("Listing packages...")

if err := dependency.ListPackage(); err != nil {
logger.WithError(err).Fatal("Cannot list packages")
}

logger.Info("Packages listed!")
},
}

func init() {
rootCmd.AddCommand(listPackagesCmd)
}
9 changes: 9 additions & 0 deletions internal/dependency/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ func Uninstall(packages *Packages, yes bool) error {
return nil
}

func ListPackage() error {
err := executor.Execute([]string{"pip", "freeze"}, &executor.ExecOptions{})
if err != nil {
return fmt.Errorf("cannot list packages in container: %w", err)
}

return nil
}

func buildInstallCmd(requirements *Requirements) []string {
cmd := []string{"pip", "install"}
if requirements.FileName != "" {
Expand Down

0 comments on commit 8852b63

Please sign in to comment.