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

dev: making starting a debugger easier. #25

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
45 changes: 45 additions & 0 deletions src/scripts/split-args.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,53 @@
#!/bin/bash
#
# This scripts allows to specify arguments for a command and it's subcommand. For example: Let's
# say we have the main command `node` and a script `./index.js` it would look like
#
# node ./index.js
#
# Let's say we want to pass-in an argument to `./index.js`
#
# node ./index.js foo
#
# And this is part of our npm scripts section in the `package.json`:
#
# {
# ...
# "scripts": {
# "start": "node ./index.js"
# }
# ...
# }
#
# By running `npm start -- foo` we can pass `foo` through to the `./index.js` script. However,
# arguments can be passed-in both to `node` and `./index.js` like this:
#
# node --inspect ./index.js foo
#
# Here `--inspect` will be passed to `node` and `foo` will be passed to `./index.js`. We can
# do that using this script by changing the `./package.json` to.
#
# {
# ...
# "scripts": {
# "start": "split-args.sh node -- ./index.js --"
# }
# ...
# }
#
# Now we can pass in arguments both to `node` and `./index.js` using separators:
#
# npm start -- --inspect -- foo
#
# Everything before the second "--" will be passed to `node` and everything after that will
# be passed to `./index.js`.
#
CMD_1=
CMD_2=
ARGS_1=
ARGS_2=
PART=0

function append () {
result=""
for part in $@; do
Expand All @@ -17,6 +61,7 @@ function append () {
done
echo $result
}

for arg in $@; do
if [[ $PART == 0 ]]; then
if [[ $arg == "--" ]]; then
Expand Down