Skip to content

Commit

Permalink
✨ 'Script info' supports version info on 'instacli' field
Browse files Browse the repository at this point in the history
  • Loading branch information
Hes-Siemelink committed Jul 14, 2024
1 parent 91b96ea commit 816e9f5
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 6 deletions.
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@

# Implementation improvements

* Script info.hidden is not documented
* Slow startup
* Serialize more Kotlin like

Expand Down
9 changes: 9 additions & 0 deletions instacli-spec/commands/instacli/script-info/Script info.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,15 @@ cli --help .
No commands available.
```

### Instacli version

You can indicate the version of the Instacli spec that the script is using.

```yaml instacli
Script info:
instacli-spec: v0.1
```

## Using types

You can define the input and output of a Script as types.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ oneOf:
type: string
"hidden":
type: boolean
"instacli-spec":
type: string
"input":
type:
- object
Expand All @@ -22,4 +24,4 @@ oneOf:
unevaluatedProperties: false
required:
- "properties"
additionalProperties: false
additionalProperties: false
20 changes: 20 additions & 0 deletions instacli-spec/language/Organizing Instacli files in directories.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,26 @@ Available commands:

### Hidden directory

You can hide the directory from the interactive command chooser by setting the `hidden` property to `true`.

For example take the following `.instacli.yaml` file in the `subcommand` directory:

```yaml file:subcommand/.instacli.yaml
Script info:
hiddent: true
```

It will not show up as a subcommand when invoking `cli --help`.

### Instacli version

You can indicate the version of the Instacli spec that the script is using.

```yaml instacli
Script info:
instacli-spec: v0.1
```

### Importing files from another directory

Out-of-the-box, you
Expand Down
3 changes: 1 addition & 2 deletions instacli-spec/language/tests/Directory tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

This contains Instacli behavior that is too boring for the main spec but should be tested.

## Directory description

## Empty directory

This is what happens when you run `cli` in an empty directory.
Expand All @@ -28,3 +26,4 @@ This is an example directory
No commands available.
```

1 change: 1 addition & 0 deletions src/main/kotlin/instacli/cli/CliFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class CliFile(val cliFile: Path) : CommandInfo, CommandHandler(asScriptCommand(c
override val name: String = asCliCommand(cliFile.name)
override val description: String by lazy { script.info?.description ?: asScriptCommand(name) }
override val hidden: Boolean by lazy { script.info?.hidden ?: false }
override val instacliSpec: String by lazy { script.info?.instacliSpec ?: "unknown" }

val script by lazy { Script.from(scriptNodes) }
private val scriptNodes: List<JsonNode> by lazy { Yaml.parse(cliFile) }
Expand Down
5 changes: 4 additions & 1 deletion src/main/kotlin/instacli/cli/DirectoryInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ import kotlin.io.path.name
class DirectoryInfo : CommandInfo {

var dir: Path = Path.of(".")
override var hidden: Boolean = false

override var hidden: Boolean = false
override var name: String = ""

@JsonProperty("Script info")
override var description: String = ""

@JsonProperty("instacli-spec")
override var instacliSpec: String = "unknown"

val imports = mutableListOf<String>()
val connections = Json.newObject()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package instacli.commands.scriptinfo

import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonProperty
import instacli.language.types.TypeReference

data class ScriptInfoData(
val description: String? = null,
val input: TypeReference? = null,
val hidden: Boolean = false
val hidden: Boolean = false,
@JsonProperty("instacli-spec")
val instacliSpec: String? = null
) {

@JsonCreator
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/instacli/language/CommandInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ interface CommandInfo {
val name: String
val description: String
val hidden: Boolean
val instacliSpec: String
}

0 comments on commit 816e9f5

Please sign in to comment.