amber-lang / amber-lang/amber

[Feature] A proper command interface

オープン
#900 コメント 1 件 リアクション 1 件 担当者 0 名 GitHub で見る
compiler
主要言語
Rust
スター
5.2k
フォーク
145
平均マージ
5日 3時間
マージ済み PR(30日)
7

説明

Shell scripting as a concept is writing a glue code that coordinates independent binaries/apps to act together as a single process. Driving this idea, the concept of external binary/app should be crystalized in a representation form in the syntax. Such representation should ideally be maintained by developers in a form of external packages. The following proposal suggests a new `app` interface which comes with copious advantages:
1. Automatically detects available version and adapts to the selected one
2. Standardizes the way script uses external apps/binaries (instead of using bash's CLI)
3. Can represent multiple small external binaries/apps at once
4. Can expose standard ways to achieve certain effects

**Is your feature request related to a problem? Please describe.**
Writing `$ cmd $` blocks should be discouraged. We should abstract away from writing Bash code in Amber. At least for the regular developers that do not develop Amber libraries. This comes with multiple drawbacks:
- Hardcoded bash snippet never adjusts to the machine it's run on
- Writing adjusting logic usually encourages to detect version every single time a function is called which slows down the performance
- Encourages to write boilerplate code that is repeated for each command

**Describe the solution you'd like**
This is why I think that some app-like interface should be introduced. The interface could loosely look like this example:
```js
// Userland
import { Seq } from "seq" // This would be some kind of a library

let my_range = Seq.range(0, 5)
for i in my_range {
// ...
}
```

The `Seq` is an interface between Amber and `seq` command. This interface comes with multiple benefits:
- It can handle different versions of `seq`
- It can work with GNU or BSD or any version of `seq` that was created
- It has an object-like nature - this is a structure with multiple methods that can interact with `seq`

Perks of this interface:
- It runs specific method once at the startup to:
- Detect if the required command is installed
- Detect the version of the command and it's platform
- Mechanics behind the scenes decide which method to run for which version

Example of such syntax (TBD):
```js
// The library that is used
app Seq {
// A required method for an app interface
fun init(): [Text]? {
// Runs bash code to return version array that is later
// lexicographically matched with defined methods for versions

// Version returned can be any value that can be
// compared lexicographically like [Int] or [Text]

// Fails if app not detected
}

// This function will run when other versions don't get matched
fun generate(self, from_value: Int, to_value: Int): [Int] {
...
}
...
}

// Interface for app in version "1.3.2" or higher
app Seq ver "1.3.2" {
// This function will run when app in version "1.3.2" or higher is detected
fun generate(self, from_value: Int, to_value: Int): [Int] {
...
}
...
}
```

App interface is always public.

**Additional context**
This should be added once we introduce OOP-like paradigm.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。