Skip to content

Commit

Permalink
Add podman-env command
Browse files Browse the repository at this point in the history
Add subcommand to setup environment variables to use `podman-remote` with
the CRC VM.

Fixes #961.
  • Loading branch information
zeenix committed Mar 4, 2020
1 parent 41f38d0 commit 8198b5d
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions cmd/crc/cmd/podman_env.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package cmd

import (
"github.com/code-ready/crc/pkg/crc/constants"
"github.com/code-ready/crc/pkg/crc/errors"
"github.com/code-ready/crc/pkg/crc/machine"
"github.com/code-ready/crc/pkg/crc/output"
"github.com/code-ready/crc/pkg/os/shell"
"github.com/spf13/cobra"
)

var podmanEnvCmd = &cobra.Command{
Use: "podman-env",
Short: "Setup podman environment",
Long: `Setup environment for 'podman' binary to access podman on CRC VM`,
Run: func(cmd *cobra.Command, args []string) {
userShell, err := shell.GetShell(forceShell)
if err != nil {
errors.ExitWithMessage(1, "Error running the podman-env command: %s", err.Error())
}

ipConfig := machine.IpConfig{
Name: constants.DefaultName,
Debug: isDebugLog(),
}

exitIfMachineMissing(ipConfig.Name)

result, err := machine.Ip(ipConfig)
if err != nil {
errors.Exit(1)
}

output.Outln(shell.GetPathEnvString(userShell, constants.CrcBinDir))
output.Outln(shell.GetEnvString(userShell, "PODMAN_USER", constants.DefaultSSHUser))
output.Outln(shell.GetEnvString(userShell, "PODMAN_HOST", result.IP))
output.Outln(shell.GetEnvString(userShell, "PODMAN_IDENTITY_FILE", constants.GetPrivateKeyPath()))
output.Outln(shell.GetEnvString(userShell, "PODMAN_IGNORE_HOSTS", "1"))
output.Outln(shell.GenerateUsageHint(userShell, "crc podman-env"))
},
}

func init() {
rootCmd.AddCommand(podmanEnvCmd)
podmanEnvCmd.Flags().StringVar(&forceShell, "shell", "", "Set the environment for the specified shell: [fish, cmd, powershell, tcsh, bash, zsh]. Default is auto-detect.")
}

0 comments on commit 8198b5d

Please sign in to comment.