Skip to content

Add raw flag #252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ name: test
on:
push:
branches:
- master
- 'release/**'
- '*'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think changes to the tests should be mixed into PRs that fix bugs or implement new features, but should be in their own PR.

I'm not sure why you would want to run tests on each push to any branch. I worry that this could use up some Github quota, so other tests may be queued later, instead of being executed right away. Not sure if that is a valid concern though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before creating PR, Github Action cannot be run at forked repo, this causes many PR with failed CI. Except that use branch release/* to create PR, it looks unreasonable.

The limit of branch to run CI, I think, it's not a good idea.

pull_request:

jobs:
Expand Down
36 changes: 34 additions & 2 deletions cmd/limactl/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ lima command is provided as an alias for limactl shell $LIMA_INSTANCE. $LIMA_INS
Hint: try --debug to show the detailed logs, if it seems hanging (mostly due to some SSH issue).
`

var shellExample = `
$ limactl shell default echo '$RANDOM'
will output a random number
$ limactl shell default --raw echo '$RANDOM'
will outoput $RANDOM
`

func newShellCommand() *cobra.Command {
var shellCmd = &cobra.Command{
Use: "shell INSTANCE [COMMAND...]",
Expand All @@ -32,11 +39,13 @@ func newShellCommand() *cobra.Command {
RunE: shellAction,
ValidArgsFunction: shellBashComplete,
SilenceErrors: true,
Example: shellExample,
}

shellCmd.Flags().SetInterspersed(false)

shellCmd.Flags().String("workdir", "", "working directory")
shellCmd.Flags().Bool("raw", false, "pass raw parament to COMMAND")
return shellCmd
}

Expand Down Expand Up @@ -109,8 +118,22 @@ func shellAction(cmd *cobra.Command, args []string) error {
logrus.Debugf("changeDirCmd=%q", changeDirCmd)

script := fmt.Sprintf("%s ; exec bash --login", changeDirCmd)

raw, err := cmd.Flags().GetBool("raw")
if err != nil {
return err
}
if len(args) > 1 {
script += fmt.Sprintf(" -c %q", shellescape.QuoteCommand(args[1:]))
tailArgs := args[1:]
escapedArgs := ""
if raw {
escapedArgs = shellescape.QuoteCommand(tailArgs)
escapedArgs = shellescape.QuoteCommand([]string{escapedArgs})
} else {
escapedArgs = strings.Join(tailArgs, " ")
escapedArgs = shellescape.QuoteCommand([]string{escapedArgs})
}
script += fmt.Sprintf(" -c %s", escapedArgs)
}

arg0, err := exec.LookPath("ssh")
Expand All @@ -126,8 +149,17 @@ func shellAction(cmd *cobra.Command, args []string) error {
// required for showing the shell prompt: https://stackoverflow.com/a/626574
sshArgs = append(sshArgs, "-t")
}

debug, err := cmd.Flags().GetBool("debug")
if err != nil {
return err
}
if debug {
sshArgs = append(sshArgs, "-v")
} else {
sshArgs = append(sshArgs, "-q")
}
sshArgs = append(sshArgs, []string{
"-q",
"-p", strconv.Itoa(inst.SSHLocalPort),
"127.0.0.1",
"--",
Expand Down