https://github.com/barcek/deye
say yes to Deno | shorthand permission passing | command-line tool | Bash
https://github.com/barcek/deye
bash command-line-tool deno dx javascript shell
Last synced: 3 months ago
JSON representation
say yes to Deno | shorthand permission passing | command-line tool | Bash
- Host: GitHub
- URL: https://github.com/barcek/deye
- Owner: barcek
- License: mit
- Created: 2022-02-04T18:49:14.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-01-16T15:06:25.000Z (over 1 year ago)
- Last Synced: 2025-02-11T11:53:03.933Z (over 1 year ago)
- Topics: bash, command-line-tool, deno, dx, javascript, shell
- Language: Shell
- Homepage:
- Size: 50.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# deye
Pass permissions to `deno run` more easily.
Generates and runs a long-form command via shorthands, with a preview option and self-test.
Available over a Deno base image via the Dockerfile in [shipping](https://github.com/barcek/shipping).
## Why?
The permissions flags are reasonably long and several might be needed to run a project. This can be a relatively large overhead when prototyping or running occasional scripts.
## How?
The `deye` command takes as its first argument a shorthand string. This is a set of characters identifying the permissions or other options required, e.g. `rwx` represents `--allow-read`, `--allow-write` and `--allow-run`.
Additional arguments usually passed directly to `deno run`, e.g. the file path and any arguments to the file, are passed to `deye` immediately after the shorthand string.
```
deye [[ ...]]
```
The shorthand string either:
- has one character per permission or other option, e.g. as above `r` to allow read, or
- is three characters long - `all` - to apply every permission at once
For the full set of shorthands available, see [Mapping](#mapping) below.
### Examples
For the `--allow-read`, `--allow-write` and `--allow-run` flags the corresponding characters are `r`, `w` and `x`:
```shell
deye rwx script.js
```
Flags taking values are simply passed after the string:
```shell
deye rw --allow-run="util" script.js
```
For `--allow-all` use `all`:
```shell
deye all script.js
```
#### Other options
The `--no-prompt`, `--no-npm`, `--no-remote`, `--config`, `--import-map`, `--check` and `--watch` options are also available, as are `--compat` and `--unstable`, since removed from Deno but retained here for backward compatibility. The former:
```shell
deye tNRCITW script.js
```
The default path for `--config` is 'deno.json', and for `--import-map` 'import_map.json', per the Deno docs. For the removed `--unstable`, a range of granular instability options exist with `--unstable`-prefixed flags.
### Preview
To see the full command generated, without running it, the `--preview` or `-p` flag can be used (see [Options](#options) below).
## Mapping
### Permissions - individual
- `e` --allow-env
- `f` --allow-ffi
- `n` --allow-net
- `i` --allow-import
- `s` --allow-sys
- `r` --allow-read
- `w` --allow-write
- `x` --allow-run
- `h` --allow-hrtime (cf. note below)
### Permissions - combined
- `all` --allow-all
### Other options
- `t` --no-prompt ('throw')
- `N` --no-npm
- `R` --no-remote
- `C` --config deno.json
- `I` --import-map=import_map.json
- `T` --check ('types')
- `W` --watch
- `c` --compat (cf. note below)
- `u` --unstable (cf. note below)
**NB** Retained for backward compatibility: `--compat` (mode removed in Deno v1.25.2); `--allow-hrtime` (removed v2.0.0); `--unstable` (removed v2.0.0).
## Source
The script can be run with the command `./deye` while in the same directory, and from elsewhere using the pattern `path/to/deye`, by first making it executable, if not already, with `chmod +x deye`. Once executable, it can be run from any directory with the simpler `deye` by placing it in a directory listed on the `$PATH` environment variable, e.g. '/bin' or '/usr/bin'.
The hashbang at the top of the file assumes the presence of Bash in '/bin', the source code that several utils and Deno itself are installed and can be invoked directly, e.g. Deno with `deno`. A list can be found close to the top of the file, and is printed also in the help text. In the event of any absence, the script will print the fact then exit.
### Defaults
The mapping is defined close to the top of the source file.
### Making changes
Running the self-test after making changes plus extending or adding test cases to cover new behaviour is recommended. The self-test is run with the `--test` or `-T` flag (see [Options](#options) below). The test cases are set in the `perform_self_test` function, which is defined with the other option handlers.
## Options
The following can be passed to `deye` before the shorthand string:
- `--preview` / `-p`, to show but not run the full command generated then exit
The following can be passed to `deye` in place of the shorthand string:
- `--show` / `-s`, to grep the `deno run` help text for the flag mapped to the next argument, e.g. for '--allow-read' with `-s r`, then exit
- `--version` / `-v`, to show name and version number then exit
- `--help` / `-h`, to show help text, incl. the shorthands available, then exit
- `--test` / `-T`, to perform the self-test then exit, returning an exit code of 1 on failure
## Streams
Sets of arguments can be piped to `deye` from another process, with each complete argument set occupying a single line and each line being handled individually.
If a batch of lines consists only of the additional arguments passed to `deno run`, the same shorthand string is used for all:
```shell
ls | grep .js | deye rwx
```
Alternatively, each line in a batch can include its own shorthand string:
```shell
echo -e "r read.js\nw write.js\nx run.js" > cmds.txt
cat cmds.txt | deye
```
## Development plan
The following are the expected next steps in the development of the code base. The general medium-term aim is a more portable and robust implementation. Pull requests are welcome for these and other potential improvements.
- modify the show option for contextual awareness
- revise for full POSIX compatibility