https://github.com/pilisp/pilisp-cli
Shared CLI code for pilisp and pilisp-native
https://github.com/pilisp/pilisp-cli
Last synced: about 2 months ago
JSON representation
Shared CLI code for pilisp and pilisp-native
- Host: GitHub
- URL: https://github.com/pilisp/pilisp-cli
- Owner: pilisp
- License: epl-2.0
- Created: 2023-03-29T19:04:41.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-06-15T04:49:18.000Z (almost 2 years ago)
- Last Synced: 2025-02-06T04:44:19.899Z (4 months ago)
- Language: Dart
- Size: 104 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
*(Repository Deprecated: See [pilisp/pilisp-monorepo](https://github.com/pilisp/pilisp-monorepo))*
Shared code for running a rudimentary command-line interface to the PiLisp programming language.
Designed originally for use with the [pilisp] and [pilisp-native] projects.
## Features
* A `cliMain` function that is designed as a proxy for your program's `main` function:
* Expects a `PLEnv` instance and your program's `main` arguments
* Provides commands for:
* Running a PiLisp REPL
* Evaluating one-off expressions
* Loading PiLisp files
* Public `repl` and `loadFile` functions for starting a PiLisp REPL and loading a PiLisp file, respectively.## Getting started
```shell
$ dart pub add pilisp_cli
```Then for your Dart program's entry-point, let's say `bin/cli.dart`:
```dart
import 'package:pilisp/pilisp.dart';
import 'package:pilisp_cli/pilisp_cli.dart' as pcli;void main(List args) {
// piLispEnv is the default provided by the pilisp package
pcli.cliMain(piLispEnv, args);
}
```Now try running a REPL:
```shell
$ dart run bin/cli.dart
pl>
```## Usage
### Dart Usage
As show in Getting Started, this is the simplest integration of the pilisp_cli package that
proxies your main handling to the `cliMain` function:```dart
import 'package:pilisp/pilisp.dart';
import 'package:pilisp_cli/pilisp_cli.dart' as pcli;void main(List args) {
// piLispEnv is the default provided by the pilisp package
pcli.cliMain(piLispEnv, args);
}
```If you do not want to use `cliMain` for parsing arguments, etc., you can use this package's
other functions directly.To start a PiLisp REPL:
```dart
import 'package:pilisp/pilisp.dart';
import 'package:pilisp_cli/pilisp_cli.dart' as pcli;void main(List args) {
// Start a REPL
pcli.repl(piLispEnv);
}
```To load a PiLisp file:
```dart
import 'package:pilisp/pilisp.dart';
import 'package:pilisp_cli/pilisp_cli.dart' as pcli;void main(List args) {
// Load a file, pass args that become *command-line-args* in PiLisp
pcli.loadFile(piLispEnv, '/path/to/a/file', args);
}
```You can also change the `piLispEnv` or create your own `PLEnv` instance and pass that to these functions. The primary reason for doing so would be to change or add default language bindings. See [this file in pilisp-native][pilisp-native-env] for a non-trivial example of extending the default `PLEnv`.
### CLI Usage
We can use the [main example] found in this project to demonstrate how the CLI behaves:
```shell
$ dart run example/pilisp_cli_main_example.dart
pl>
``````shell
$ dart run example/pilisp_cli_main_example.dart load --file example/example.pil a b c
Scripted, you passed in 6 command-line arguments: load, --file, example/example.pil, a, b, c
```## Additional information
Read up on PiLisp in these repositories:
* [pilisp]
* [pilisp-native]## License
Copyright © Daniel Gregoire 2023
[Eclipse Public License - v 2.0](https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt)
THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE
PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION
OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.### Exceptions
**Project:** cli\_repl
The cli\_repl code in this project has been copied and adapted from the [cli_repl](https://github.com/jathak/cli_repl) library by Jennifer Thakar, which is licensed under BSD 3-Clause "New" or "Revised" License.
[main example]: https://github.com/pilisp/pilisp-cli/blob/main/example/pilisp_cli_main_example.dart
[pilisp]: https://github.com/pilisp/pilisp
[pilisp-native]: https://github.com/pilisp/pilisp-native
[pilisp-native-env]: https://github.com/pilisp/pilisp-native/blob/main/lib/src/pilisp_native_public.dart