Skip to content

Commit

Permalink
change make logs quiet by default and adds a verbose flag to enable v…
Browse files Browse the repository at this point in the history
…erbose log output

Signed-off-by: olalekan odukoya <[email protected]>
  • Loading branch information
olamilekan000 committed Dec 24, 2024
1 parent 16f4051 commit 5cf98de
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions cmd/limactl/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func newCopyCommand() *cobra.Command {
}

copyCommand.Flags().BoolP("recursive", "r", false, "copy directories recursively")
copyCommand.Flags().BoolP("verbose", "v", false, "enable verbose output")

return copyCommand
}
Expand All @@ -43,23 +44,33 @@ func copyAction(cmd *cobra.Command, args []string) error {
return err
}

arg0, err := exec.LookPath("scp")
verbose, err := cmd.Flags().GetBool("verbose")
if err != nil {
return err
}
instances := make(map[string]*store.Instance)
scpFlags := []string{}
scpArgs := []string{}

debug, err := cmd.Flags().GetBool("debug")
if err == nil && debug {
verbose = true
}

arg0, err := exec.LookPath("scp")
if err != nil {
return err
}
if debug {
scpFlags = append(scpFlags, "-v")

instances := make(map[string]*store.Instance)
scpFlags := []string{}
scpArgs := []string{}

if !verbose {
scpFlags = append(scpFlags, "-q")
}

if recursive {
scpFlags = append(scpFlags, "-r")
}

legacySSH := sshutil.DetectOpenSSHVersion().LessThan(*semver.New("8.0.0"))
for _, arg := range args {
path := strings.Split(arg, ":")
Expand Down Expand Up @@ -117,9 +128,11 @@ func copyAction(cmd *cobra.Command, args []string) error {

sshCmd := exec.Command(arg0, append(sshArgs, scpArgs...)...)
sshCmd.Stdin = cmd.InOrStdin()
sshCmd.Stdout = cmd.OutOrStdout()
sshCmd.Stderr = cmd.ErrOrStderr()
logrus.Debugf("executing scp (may take a long time)): %+v", sshCmd.Args)
if verbose {
sshCmd.Stdout = cmd.OutOrStdout()
sshCmd.Stderr = cmd.ErrOrStderr()
logrus.Debugf("executing scp (may take a long time): %+v", sshCmd.Args)
}

// TODO: use syscall.Exec directly (results in losing tty?)
return sshCmd.Run()
Expand Down

0 comments on commit 5cf98de

Please sign in to comment.