Skip to content

Commit

Permalink
Try explore (#79)
Browse files Browse the repository at this point in the history
* Add try explore to readme

* use current shell with try explore

* Update readme for try -D path explore

* update readme for try explore

* Add an expect test for explore

* debugging (working locally)

* debug

* debug

* see expect version

* debug

* fix?

* debug :)

* fix?

* Hide output (seems to be working)

* debug

* fix

* Add try explore to manpages

* Add bash completions for try explore

---------

Co-authored-by: Konstantinos Kallas <[email protected]>
Co-authored-by: gliargovas <[email protected]>
  • Loading branch information
3 people authored Jun 29, 2023
1 parent 95471fe commit 6059bac
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 3 deletions.
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";;
(--) shift; try "$@";;
(*) try "$@";;
esac
Expand Down

0 comments on commit 6059bac

Please sign in to comment.