Skip to content
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

Try explore #79

Merged
merged 20 commits into from
Jun 29, 2023
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
run: |
uname -a
sudo apt-get update
sudo apt-get install strace
sudo apt-get install strace expect

- name: Checkout
uses: actions/checkout@v2
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ You can also choose to commit the overlay directory contents:
$ try commit rustup-sandbox
```

You can also run `try explore` to open your current shell in try, or `/try
explore /tmp/tmp.X6OQb5tJwr` to explore an existing sandbox.

## Known Issues
Any command that interacts with other users/groups will fail since only the
current user's UID/GID are mapped. However, the [future
Expand Down
2 changes: 1 addition & 1 deletion completions/try.bash
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ _try() {

case "${cmd}" in
try)
opts="-n -y -v -h -D summary commit"
opts="-n -y -v -h -D summary commit explore"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down
5 changes: 5 additions & 0 deletions docs/try.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ try - run a command in an overlay
| try [-n] [-D DIR] CMD [ARG ...]
| try summary [DIR]
| try commit [DIR]
| try explore
| try -v
| try -h

Expand Down Expand Up @@ -53,6 +54,10 @@ try commit *DIR*

: Commit the overlay in DIR

try explore

: Run in interactive mode

## Arguments

*CMD*
Expand Down
42 changes: 42 additions & 0 deletions test/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,47 @@ EOF
diff -q expected.out out.txt
}

test_explore()
{
local try_workspace=$1
cd "$try_workspace/"

export SHELL="/bin/bash"

echo hi >expected.out

cat >explore.exp <<EOF
#!/usr/bin/expect

set timeout 3

spawn "$try" explore
expect {
## Ignore the warnings
"Warning*" {
exp_continue
}
## When we get the prompt, send the command
"#*" {
send -- "echo hi>test.txt\r"
}
}
expect "#"
## Send `exit`
send \x04

## Ignore all output and just send a y at the end
expect ""
expect "Commit*"
send -- "y\r"
expect eof
EOF
## Debug using the -d flag
expect explore.exp >/dev/null

diff -q expected.out test.txt
}

test_summary()
{
local try_workspace=$1
Expand Down Expand Up @@ -228,6 +269,7 @@ if [ "$#" -eq 0 ]; then
run_test test_pipeline
run_test test_cmd_sbst_and_var
run_test test_summary
run_test test_explore
run_test test_empty_summary
run_test test_mkdir_on_file

Expand Down
2 changes: 1 addition & 1 deletion try
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ fi
case "$1" in
(summary) : ${SANDBOX_DIR=$2}; summary;;
(commit) : ${SANDBOX_DIR=$2}; commit;;
(explore) : ${SANDBOX_DIR=$2}; try bash;;
(explore) : ${SANDBOX_DIR=$2}; try "$SHELL";;
angelhof marked this conversation as resolved.
Show resolved Hide resolved
(--) shift; try "$@";;
(*) try "$@";;
esac
Expand Down