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

[Feature] Remove script name from arguments passed to main block #564

Open
hdwalters opened this issue Nov 3, 2024 · 0 comments
Open

[Feature] Remove script name from arguments passed to main block #564

hdwalters opened this issue Nov 3, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@hdwalters
Copy link
Contributor

hdwalters commented Nov 3, 2024

Is your feature request related to a problem? Please describe.
When command line arguments are passed to a Bash script, the $@ array contains only the arguments:

hwalters@Ghostwheel ~/git/amber (improve-command-line-interface) 
$ cat args.sh
#!/usr/bin/env bash
for arg in "$@"; do
    echo $arg
done
hwalters@Ghostwheel ~/git/amber (improve-command-line-interface) 
$ ./args.sh 1 2 3
1
2
3

However, when command line arguments are passed to an Amber script, the array passed to the main block contains the executable name bash as well. Note, this requires changes on my feature branch to pass command line arguments, as described in issue #411:

hwalters@Ghostwheel ~/git/amber (improve-command-line-interface) 
$ cat args.ab
#!/usr/bin/env amber
main(args) {
    for arg in args {
        echo arg
    }
}
hwalters@Ghostwheel ~/git/amber (improve-command-line-interface) 
$ ./args.ab 1 2 3
bash
1
2
3

This is inconsistent, and will cause confusion among users. Additionally, we get no extra information from the contents of the $0 variable, as it will only ever contain bash.

Describe the solution you'd like
I would like the Amber script to be passed the command line arguments only, for consistency with Bash scripts.

I would also like to add a standard library function to partition the command line arguments into positional parameters and options (starting - or --):

pub fun partition_args(args: [Text], ref params: [Text], ref options: [Text]): Null {
    ...
}

Describe alternatives you've considered
N/A

Additional context
This is occurring because the main block is explicitly passed $0 as well as $@:

#!/usr/bin/env bash
# Written in [Amber](https://amber-lang.com/)
# version: 0.3.5-alpha
# date: 2024-11-03 10:34:32
# #!/usr/bin/env amber
args=("$0" "$@")
for arg in "${args[@]}"; do
    echo "${arg}"
done
@hdwalters hdwalters added the enhancement New feature or request label Nov 3, 2024
@hdwalters hdwalters self-assigned this Nov 3, 2024
@github-project-automation github-project-automation bot moved this to 🆕 New in Amber Project Nov 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant