Skip to content

Commit

Permalink
Add status 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 6, 2020
1 parent c8ea9c2 commit 1e65df0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
27 changes: 27 additions & 0 deletions cmd/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package cmd

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

var statusCmd = &cobra.Command{
Use: "status",
Short: "Show the current active virtual environment",
Run: func(cmd *cobra.Command, args []string) {
logger := log.Logger
err := log.SetupLogger(cmd)
if err != nil {
logger.WithError(err).Fatal("Cannot setup logger")
}

if err := environment.Status(); err != nil {
logger.WithError(err).Fatal("Cannot show current active virtual environment")
}
},
}

func init() {
rootCmd.AddCommand(statusCmd)
}
12 changes: 12 additions & 0 deletions internal/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,18 @@ func Create(conf *Config) error {
return nil
}

func Status() error {
logger := log.Logger
envName := getCurrentEnv()
if envName == "" {
logger.Info("No active environment")
return nil
}

logger.Infof("Active environment: %s", envName)
return nil
}

func Activate(envName string) error {
logger := log.Logger
cli, err := client.NewClientWithOpts(client.FromEnv)
Expand Down

0 comments on commit 1e65df0

Please sign in to comment.