Skip to content

Commit

Permalink
added bash completion feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Legion2 committed Apr 19, 2020
1 parent a23dbc2 commit ebf52ae
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 19 deletions.
33 changes: 20 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
name: Build

on: [ push, pull_request ]
on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Java JDK 8
uses: actions/[email protected]
with:
java-version: 8
- name: Gradle Build
run: gradle build
- name: Upload distribution archive
uses: actions/upload-artifact@v2-preview
with:
name: open-cue-cli.zip
path: build/distributions/open-cue-cli.zip
- uses: actions/checkout@v2
- name: Setup Java JDK 8
uses: actions/[email protected]
with:
java-version: 8
- name: Gradle Build
run: gradle build
- name: Generate Bash Completion
env:
OPEN_CUE_CLI_COMPLETE: bash
run: |
unzip build/distributions/open-cue-cli.zip
./open-cue-cli/open-cue-cli > open-cue-cli/bash-complete-open-cue-cli.sh
chmod +x open-cue-cli/bash-complete-open-cue-cli.sh
- name: Upload distribution archive
uses: actions/upload-artifact@v2-preview
with:
name: open-cue-cli
path: open-cue-cli/
10 changes: 9 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ jobs:
java-version: 8
- name: Gradle Build
run: gradle build
- name: Generate Bash Completion
env:
OPEN_CUE_CLI_COMPLETE: bash
run: |
unzip build/distributions/open-cue-cli.zip
./open-cue-cli/open-cue-cli > open-cue-cli/bash-complete-open-cue-cli.sh
chmod +x open-cue-cli/bash-complete-open-cue-cli.sh
zip open-cue-cli.zip open-cue-cli
- name: Get upload url
id: release-id
run: |
Expand All @@ -27,6 +35,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.release-id.outputs.upload_url }}
asset_path: build/distributions/open-cue-cli.zip
asset_path: open-cue-cli.zip
asset_name: open-cue-cli.zip
asset_content_type: application/zip
3 changes: 1 addition & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ Test=245
```
Profile names **MUST** only contain normal characters "a-z", "A-Z" and "_".
Also don't use language specific characters like ä and é.
You must set the name of the profile, when you export it from iCUE, you can't change it later, because it's stored inside the profile file.
The priorities comes into play when you activate two profiles, then the profile with the higher priority is shown on top of the other.

> `default` is not allowed as profile name.
## Packaging of this application
This package is provide as zip containing executables and dependencies as jars.
A Java Runtime Environment (JRE) must be installed to run the application.
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
jvmTarget = "1.8"
languageVersion = "1.3"
apiVersion = "1.3"
freeCompilerArgs += "-Xopt-in=com.github.ajalt.clikt.completion.ExperimentalCompletionCandidates"
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/io/github/legion2/open_cue_cli/OpenCueCli.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.legion2.open_cue_cli

import com.github.ajalt.clikt.completion.CompletionCandidates
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.options.default
Expand All @@ -9,7 +10,7 @@ import com.github.ajalt.clikt.parameters.types.int
import com.github.ajalt.clikt.parameters.types.restrictTo
import io.github.legion2.open_cue_cli.CliContext.Companion.createCliContext

class OpenCueCli : CliktCommand(name = "open-cue-cli") {
class OpenCueCli : CliktCommand(name = "open-cue-cli", autoCompleteEnvvar = "OPEN_CUE_CLI_COMPLETE") {
private val port: Int by option("-p", "--port", help = "Port of the Open CUE Service", metavar = "<port>")
.int().restrictTo(min = 0).default(25555)
private val host: String by option("-H", "--host", help = "Hostname or ip address of the Open CUE Service",
Expand All @@ -28,4 +29,5 @@ val <T> Iterable<T>.echoString: String get() = joinToString("\n")

fun <T> Iterable<T>.echoString(transform: (T) -> CharSequence): String = joinToString("\n", transform = transform)

fun CliktCommand.profileArgument(help: String? = null) = argument("profile", help = help ?: "The name of the profile")
fun CliktCommand.profileArgument(help: String? = null) = argument("profile", help = help ?: "The name of the profile",
completionCandidates = CompletionCandidates.Custom.fromStdout("(test -x ./open-cue-cli && ./open-cue-cli profile list) || (hash open-cue-cli 2>/dev/null && open-cue-cli profile list)"))
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ class ListProfiles : CliktCommand("List all available profiles for the current g
private val cliContext by requireObject<CliContext>()
override fun run() = runBlocking {
val profiles = cliContext.sdkClient.listProfiles()
echo(profiles.sortedBy { it.priority }.echoString { profile -> if (details) profile.echoString else profile.name })
echo(profiles.sortedBy { it.priority }.echoString { profile -> if (details) profile.echoString else profile.name }, lineSeparator = "\n")
}
}

0 comments on commit ebf52ae

Please sign in to comment.