├── .gitattributes ├── .github ├── FUNDING.yml ├── dependabot.yml └── workflows │ ├── build.yml │ └── release.yml ├── .gitignore ├── LICENSE ├── Readme.md ├── build.gradle.kts ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle.kts └── src └── main └── kotlin └── io └── github └── legion2 └── open_cue_cli ├── CliContext.kt ├── Main.kt ├── OpenCueCli.kt ├── OpenCueConsole.kt ├── client ├── CueSdkHttpServer.kt ├── GameSdkError.kt └── SdkHttpServerException.kt ├── model ├── Profile.kt └── SdkDetails.kt ├── profile ├── ActivateProfile.kt ├── DeactivateProfile.kt ├── ListProfiles.kt ├── ProfileCommand.kt ├── ProfileInfo.kt └── TriggerProfile.kt └── sdk ├── CurrentProfilesDirectoryName.kt ├── DeactivateAllProfiles.kt ├── SdkCommand.kt ├── SdkControl.kt ├── SdkInfo.kt └── StopAllEvents.kt /.gitattributes: -------------------------------------------------------------------------------- 1 | gradlew binary 2 | gradlew.bat binary -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: Legion2 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: paypal.me/LeonKiefer 13 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "gradle" 4 | directory: "/" 5 | schedule: 6 | interval: "daily" 7 | - package-ecosystem: "github-actions" 8 | directory: "/" 9 | schedule: 10 | interval: "daily" 11 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v4 10 | - name: Setup Java JDK 11 | uses: actions/setup-java@v4 12 | with: 13 | distribution: temurin 14 | java-version: 17 15 | - name: Gradle Build 16 | run: ./gradlew runtimeZip 17 | - name: Upload distribution archive 18 | uses: actions/upload-artifact@v4 19 | with: 20 | name: open-cue-cli 21 | path: build/open-cue-cli-*.zip 22 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | release: 5 | types: [published] 6 | 7 | jobs: 8 | upload: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v4 12 | - name: Setup Java JDK 13 | uses: actions/setup-java@v4 14 | with: 15 | distribution: temurin 16 | java-version: 17 17 | - name: Gradle Build 18 | run: ./gradlew runtimeZip 19 | - name: Get upload url 20 | id: release-id 21 | run: | 22 | RELEASE_ID=$(jq --raw-output '.release.id' $GITHUB_EVENT_PATH) 23 | echo "::set-output name=upload_url::https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets{?name,label}" 24 | - name: Upload Release Assets 25 | id: upload-release-asset 26 | uses: bgpat/release-asset-action@03b0c30db1c4031ce3474740b0e4275cd7e126a3 27 | with: 28 | pattern: build/open-cue-cli-*.zip 29 | github-token: ${{ secrets.GITHUB_TOKEN }} 30 | release-url: ${{ steps.release-id.outputs.upload_url }} 31 | allow-overwrite: true 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | *.ipr 3 | .idea/ 4 | .gradle/ 5 | build/ 6 | out/ 7 | 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # Open CUE CLI [![Build](https://github.com/Legion2/open-cue-cli/workflows/Build/badge.svg)](https://github.com/Legion2/open-cue-cli/actions?query=workflow%3ABuild) 2 | Command Line Interface (CLI) to change iCUE profiles from the command line and play multiple profiles at once. 3 | This CLI uses the iCUE Game SDK via the [Open CUE Service](https://github.com/Legion2/open-cue-service). 4 | You can use all your customized iCUE profiles. 5 | 6 | ## Getting Started 7 | Download and start the [Open CUE Service](https://github.com/Legion2/open-cue-service). 8 | Download the [latest release](https://github.com/Legion2/open-cue-cli/releases/latest) of Open CUE CLI and extract the archive. 9 | Call the cli tool `open-cue-cli.bat` or `open-cue-cli` from a command prompt with the option `--help`. 10 | 11 | ``` 12 | Usage: open-cue-cli [OPTIONS] COMMAND [ARGS]... 13 | 14 | Options: 15 | -p, --port Port of the Open CUE Service 16 | -H, --host Hostname or ip address of the Open CUE Service 17 | --version Show the version and exit 18 | -h, --help Show this message and exit 19 | 20 | Commands: 21 | sdk 22 | profile 23 | ``` 24 | 25 | ### Examples 26 | Activates the profile `Fire` 27 | ``` 28 | > open-cue-cli profile activate Fire 29 | ``` 30 | 31 | Lists all profiles 32 | ``` 33 | > open-cue-cli profile list 34 | ``` 35 | 36 | Plays the profile `Wave` as event for a short time 37 | ``` 38 | > open-cue-cli profile trigger Wave 39 | ``` 40 | 41 | ### Profiles 42 | All profiles that you want to use with the Open CUE CLI must be in the iCUE `GameSdkEffects` directory. 43 | On Windows this is `C:\ProgramData\Corsair\CUE4\GameSdkEffects` for iCUE 4. 44 | These profiles are just the exported files when you export a profile in iCUE. 45 | When export profiles from iCUE only select "Lighting Effects" in the export settings. 46 | 47 | Profiles are grouped into directories, which normally belong to games because the SDK was designed for iCUE Game integration. 48 | Each subdirectory of `GameSdkEffects` is a group of profiles and contains a `priorities.cfg` file. 49 | 50 | ### Use own profiles/effects 51 | The subdirectories of `GameSdkEffects` normally correspond to games, but you can also create own subdirectories. 52 | If you want to add your own profiles/effects, create a new directory in the `GameSdkEffects` directory called `profiles`. 53 | Create a new text file named `priorities.cfg` in the `profiles` directory. 54 | 55 | > In Windows Administrator permissions are required to create new files in the directory, so you may create the file in another directory and then move it in the `profiles` directory. 56 | 57 | The file must contain all profile names one per line with a unique priority value. 58 | ```properties 59 | MyProfile=3 60 | Other_Profile=8 61 | Test=245 62 | ``` 63 | Profile names **MUST** only contain normal characters "a-z", "A-Z" and "_". 64 | Also don't use language specific characters such as ä and é. 65 | You must set the name of the profile before exporting it from iCUE, you can't change it later, because it is stored inside the profile file. 66 | The priorities comes into play when you activate two profiles, then the profile with the higher priority is shown on top of the other. 67 | 68 | ## Troubleshooting 69 | See [Open CUE Service Troubleshooting](https://github.com/Legion2/open-cue-service#troubleshooting) 70 | 71 | ## Packaging of this application 72 | This package is provided as zip containing optimized executable runtime image. 73 | Just download the [zip archive for your platform](https://github.com/Legion2/open-cue-cli/releases), extract it where you want and then execute one of the executable scripts from the extracted archive. 74 | 75 | You can also build the project yourself: `./gradlew runtimeZip` 76 | The output can be found in the `build` directory. 77 | 78 | ### Why not provide native executable 79 | Native executables require curl or other native implementations to do http calls. 80 | The linking in kotlin is very complex and dynamic linking is uncommon on Windows. 81 | I didn't find a way to statically link curl into to the windows native executable produced by kotlin. 82 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | val kotlinVersion = "2.0.20" 3 | kotlin("jvm") version kotlinVersion 4 | kotlin("plugin.serialization") version kotlinVersion 5 | application 6 | id("org.beryx.runtime") version "1.13.1" 7 | } 8 | 9 | repositories { 10 | mavenCentral() 11 | maven("https://kotlin.bintray.com/ktor") 12 | } 13 | 14 | application { 15 | mainClass.set("io.github.legion2.open_cue_cli.MainKt") 16 | executableDir = "" 17 | applicationName = "open-cue-cli" 18 | } 19 | 20 | runtime { 21 | addOptions("--strip-debug", "--compress", "2", "--no-header-files", "--no-man-pages") 22 | addModules( 23 | "java.base", 24 | "java.sql",//because of gson 25 | "jdk.unsupported"//https://stackoverflow.com/questions/61727613/unexpected-behaviour-from-gson 26 | ) 27 | 28 | imageZip.set(file("$buildDir/${project.application.applicationName}.zip")) 29 | targetPlatform("linux-x64") { 30 | setJdkHome(jdkDownload("https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.3%2B7/OpenJDK17U-jdk_x64_linux_hotspot_17.0.3_7.tar.gz")) 31 | } 32 | targetPlatform("linux-aarch64") { 33 | setJdkHome(jdkDownload("https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.3%2B7/OpenJDK17U-jdk_aarch64_linux_hotspot_17.0.3_7.tar.gz")) 34 | } 35 | targetPlatform("linux-arm32") { 36 | setJdkHome(jdkDownload("https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.3%2B7/OpenJDK17U-jdk_arm_linux_hotspot_17.0.3_7.tar.gz")) 37 | } 38 | targetPlatform("windows-x64") { 39 | setJdkHome(jdkDownload("https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.3%2B7/OpenJDK17U-jdk_x64_windows_hotspot_17.0.3_7.zip")) 40 | } 41 | targetPlatform("mac-x64") { 42 | setJdkHome(jdkDownload("https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.3%2B7/OpenJDK17U-jdk_x64_mac_hotspot_17.0.3_7.tar.gz")) 43 | } 44 | targetPlatform("mac-aarch64") { 45 | setJdkHome(jdkDownload("https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.3%2B7/OpenJDK17U-jdk_aarch64_mac_hotspot_17.0.3_7.tar.gz")) 46 | } 47 | } 48 | 49 | val ktorVersion = "2.3.11" 50 | val cliktVersion = "3.5.4" 51 | 52 | dependencies { 53 | implementation("com.github.ajalt.clikt:clikt:$cliktVersion") 54 | implementation("io.ktor:ktor-client-core:$ktorVersion") 55 | implementation("io.ktor:ktor-client-cio:$ktorVersion") 56 | implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion") 57 | implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion") 58 | } 59 | 60 | tasks.withType { 61 | kotlinOptions { 62 | jvmTarget = "17" 63 | languageVersion = "1.7" 64 | apiVersion = "1.7" 65 | } 66 | } 67 | 68 | val generateCliCompletions by tasks.registering(JavaExec::class) { 69 | dependsOn("classes") 70 | classpath = sourceSets.main.get().runtimeClasspath 71 | main = application.mainClass.get() 72 | environment("OPEN_CUE_CLI_COMPLETE", "bash") 73 | 74 | val completions = file("$buildDir/completions") 75 | outputs.dir(completions) 76 | doFirst { 77 | completions.mkdirs() 78 | standardOutput = File(completions, "bash-complete-open-cue-cli.sh").outputStream() 79 | } 80 | } 81 | 82 | distributions { 83 | main { 84 | contents { 85 | from(generateCliCompletions) 86 | } 87 | } 88 | } 89 | 90 | tasks.withType { 91 | gradleVersion = "7.3" 92 | distributionType = Wrapper.DistributionType.ALL 93 | } 94 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Legion2/open-cue-cli/1ba255c26467a84af39ee50095a0d4bab1b5c7cf/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Legion2/open-cue-cli/1ba255c26467a84af39ee50095a0d4bab1b5c7cf/gradlew -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "open-cue-cli" 2 | -------------------------------------------------------------------------------- /src/main/kotlin/io/github/legion2/open_cue_cli/CliContext.kt: -------------------------------------------------------------------------------- 1 | package io.github.legion2.open_cue_cli 2 | 3 | import io.github.legion2.open_cue_cli.client.CueSdkHttpServer 4 | 5 | class CliContext( 6 | val sdkClient: CueSdkHttpServer) { 7 | companion object { 8 | fun createCliContext(host: String, port: Int): CliContext { 9 | return CliContext(CueSdkHttpServer(host, port)) 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /src/main/kotlin/io/github/legion2/open_cue_cli/Main.kt: -------------------------------------------------------------------------------- 1 | package io.github.legion2.open_cue_cli 2 | 3 | import com.github.ajalt.clikt.core.subcommands 4 | import io.github.legion2.open_cue_cli.profile.* 5 | import io.github.legion2.open_cue_cli.sdk.* 6 | 7 | fun createCLI(): OpenCueCli { 8 | return OpenCueCli().subcommands( 9 | SdkCommand().subcommands( 10 | SdkInfo(), 11 | CurrentProfilesDirectoryName(), 12 | SdkControl(), 13 | StopAllEvents(), 14 | DeactivateAllProfiles() 15 | ), 16 | ProfileCommand().subcommands( 17 | ListProfiles(), 18 | ProfileInfo(), 19 | ActivateProfile(), 20 | DeactivateProfile(), 21 | TriggerProfile() 22 | )) 23 | } 24 | 25 | fun main(args: Array) = createCLI().main(args) 26 | -------------------------------------------------------------------------------- /src/main/kotlin/io/github/legion2/open_cue_cli/OpenCueCli.kt: -------------------------------------------------------------------------------- 1 | package io.github.legion2.open_cue_cli 2 | 3 | import com.github.ajalt.clikt.completion.CompletionCandidates 4 | import com.github.ajalt.clikt.core.CliktCommand 5 | import com.github.ajalt.clikt.core.context 6 | import com.github.ajalt.clikt.parameters.arguments.argument 7 | import com.github.ajalt.clikt.parameters.options.default 8 | import com.github.ajalt.clikt.parameters.options.option 9 | import com.github.ajalt.clikt.parameters.options.versionOption 10 | import com.github.ajalt.clikt.parameters.types.int 11 | import com.github.ajalt.clikt.parameters.types.restrictTo 12 | import io.github.legion2.open_cue_cli.CliContext.Companion.createCliContext 13 | 14 | class OpenCueCli : CliktCommand(name = "open-cue-cli", autoCompleteEnvvar = "OPEN_CUE_CLI_COMPLETE") { 15 | private val port: Int by option("-p", "--port", help = "Port of the Open CUE Service", metavar = "") 16 | .int().restrictTo(min = 0).default(25555) 17 | private val host: String by option("-H", "--host", help = "Hostname or ip address of the Open CUE Service", 18 | metavar = "").default("localhost") 19 | 20 | init { 21 | versionOption("1.0.0") 22 | context { 23 | console = OpenCueConsole() 24 | } 25 | } 26 | 27 | override fun run() { 28 | currentContext.findOrSetObject { createCliContext(host, port) } 29 | } 30 | } 31 | 32 | val Iterable.echoString: String get() = joinToString("\n") 33 | 34 | fun Iterable.echoString(transform: (T) -> CharSequence): String = joinToString("\n", transform = transform) 35 | 36 | fun CliktCommand.profileArgument(help: String? = null) = argument("profile", help = help ?: "The name of the profile", 37 | 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)")) 38 | -------------------------------------------------------------------------------- /src/main/kotlin/io/github/legion2/open_cue_cli/OpenCueConsole.kt: -------------------------------------------------------------------------------- 1 | package io.github.legion2.open_cue_cli 2 | 3 | import com.github.ajalt.clikt.output.CliktConsole 4 | import com.github.ajalt.clikt.output.defaultCliktConsole 5 | 6 | class OpenCueConsole : CliktConsole by defaultCliktConsole() { 7 | override val lineSeparator: String get() = "\n" 8 | } 9 | -------------------------------------------------------------------------------- /src/main/kotlin/io/github/legion2/open_cue_cli/client/CueSdkHttpServer.kt: -------------------------------------------------------------------------------- 1 | package io.github.legion2.open_cue_cli.client 2 | 3 | import io.github.legion2.open_cue_cli.model.Profile 4 | import io.github.legion2.open_cue_cli.model.SdkDetails 5 | import io.ktor.client.* 6 | import io.ktor.client.call.* 7 | import io.ktor.client.plugins.* 8 | import io.ktor.client.plugins.contentnegotiation.* 9 | import io.ktor.client.request.* 10 | import io.ktor.client.statement.* 11 | import io.ktor.http.* 12 | import io.ktor.serialization.kotlinx.json.* 13 | import kotlinx.serialization.decodeFromString 14 | import kotlinx.serialization.json.Json 15 | import java.net.ConnectException 16 | 17 | class CueSdkHttpServer(private val host: String = "localhost", private val port: Int = 25555) { 18 | private val client = HttpClient { 19 | install(ContentNegotiation) { 20 | json() 21 | } 22 | expectSuccess = true 23 | HttpResponseValidator { 24 | handleResponseExceptionWithRequest { exception, _ -> 25 | when (exception) { 26 | is ClientRequestException -> throw GameSdkError(exception.response.body()) 27 | is ResponseException -> throw SdkHttpServerException( 28 | "Server can not process request: ${exception.response.call.request.url}", 29 | exception 30 | ) 31 | is ConnectException -> throw SdkHttpServerException( 32 | "Can not send request to Open CUE Service\n" 33 | + "Make sure the Open CUE Service is running.", exception 34 | ) 35 | } 36 | } 37 | } 38 | } 39 | 40 | private fun url(path: String, parameters: Map = emptyMap()): Url { 41 | val httpParameters = parameters.entries.fold(ParametersBuilder()) { builder, (key, value) -> 42 | builder.append(key, value) 43 | builder 44 | }.build() 45 | return URLBuilder(host = host, port = port, parameters = httpParameters, pathSegments = listOf(path)).build() 46 | } 47 | 48 | suspend fun currentProfilesDirectoryName(): String = client.get(url("api/sdk/profiles-directory-name")).body() 49 | 50 | suspend fun sdkInfo(): SdkDetails = client.get(url("api/sdk/details")).body() 51 | 52 | suspend fun getControl(): Boolean = client.get(url("api/sdk/control")).body() 53 | 54 | suspend fun setControl(value: Boolean): Boolean = client.put(url("api/sdk/control/${value}")).body() 55 | 56 | suspend fun clearAllEvents(): Unit = client.post(url("api/sdk/stop-all-events")).body() 57 | 58 | suspend fun deactivateAll(): Unit = client.post(url("api/sdk/deactivate-all-profiles")).body() 59 | 60 | suspend fun listProfiles(): List = client.get(url("api/profiles")).body() 61 | 62 | suspend fun getProfile(profile: String): Profile = client.get(url("api/profiles/${profile}")).body() 63 | 64 | suspend fun trigger(profile: String): Profile = client.post(url("api/profiles/${profile}/trigger")).body() 65 | 66 | suspend fun activate(profile: String): Profile = client.put(url("api/profiles/${profile}/state/true")).body() 67 | 68 | suspend fun deactivate(profile: String): Profile = client.put(url("api/profiles/${profile}/state/false")).body() 69 | } 70 | -------------------------------------------------------------------------------- /src/main/kotlin/io/github/legion2/open_cue_cli/client/GameSdkError.kt: -------------------------------------------------------------------------------- 1 | package io.github.legion2.open_cue_cli.client 2 | 3 | import com.github.ajalt.clikt.core.CliktError 4 | 5 | class GameSdkError(override val message: String?, override val cause: Throwable? = null) : CliktError() -------------------------------------------------------------------------------- /src/main/kotlin/io/github/legion2/open_cue_cli/client/SdkHttpServerException.kt: -------------------------------------------------------------------------------- 1 | package io.github.legion2.open_cue_cli.client 2 | 3 | import com.github.ajalt.clikt.core.CliktError 4 | 5 | class SdkHttpServerException(override val message: String?, override val cause: Throwable?) : CliktError() -------------------------------------------------------------------------------- /src/main/kotlin/io/github/legion2/open_cue_cli/model/Profile.kt: -------------------------------------------------------------------------------- 1 | package io.github.legion2.open_cue_cli.model 2 | 3 | import kotlinx.serialization.Serializable 4 | 5 | @Serializable 6 | data class Profile(val name: String, val priority: Int, val state: Boolean) 7 | 8 | val Profile.echoString: String get() = "$name $priority ${if (state) "active" else "not active"}" 9 | 10 | -------------------------------------------------------------------------------- /src/main/kotlin/io/github/legion2/open_cue_cli/model/SdkDetails.kt: -------------------------------------------------------------------------------- 1 | package io.github.legion2.open_cue_cli.model 2 | 3 | import kotlinx.serialization.Serializable 4 | 5 | @Serializable 6 | data class SdkDetails( 7 | val sdkVersion: String, 8 | val serverVersion: String, 9 | val sdkProtocolVersion: Int, 10 | val serverProtocolVersion: Int, 11 | val breakingChanges: Boolean, 12 | ) 13 | -------------------------------------------------------------------------------- /src/main/kotlin/io/github/legion2/open_cue_cli/profile/ActivateProfile.kt: -------------------------------------------------------------------------------- 1 | package io.github.legion2.open_cue_cli.profile 2 | 3 | import com.github.ajalt.clikt.core.CliktCommand 4 | import com.github.ajalt.clikt.core.requireObject 5 | import com.github.ajalt.clikt.parameters.options.flag 6 | import com.github.ajalt.clikt.parameters.options.option 7 | import io.github.legion2.open_cue_cli.CliContext 8 | import io.github.legion2.open_cue_cli.model.echoString 9 | import io.github.legion2.open_cue_cli.profileArgument 10 | import kotlinx.coroutines.runBlocking 11 | 12 | class ActivateProfile : CliktCommand(name = "activate") { 13 | private val disableOther by option("-d", "--disable-other", help = "Deactivate all profiles before activating this profile").flag() 14 | private val profile by profileArgument() 15 | private val cliContext by requireObject() 16 | override fun run(): Unit = runBlocking { 17 | if (disableOther) { 18 | cliContext.sdkClient.deactivateAll() 19 | } 20 | echo(cliContext.sdkClient.activate(profile).echoString) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/kotlin/io/github/legion2/open_cue_cli/profile/DeactivateProfile.kt: -------------------------------------------------------------------------------- 1 | package io.github.legion2.open_cue_cli.profile 2 | 3 | import com.github.ajalt.clikt.core.CliktCommand 4 | import com.github.ajalt.clikt.core.requireObject 5 | import io.github.legion2.open_cue_cli.CliContext 6 | import io.github.legion2.open_cue_cli.model.echoString 7 | import io.github.legion2.open_cue_cli.profileArgument 8 | import kotlinx.coroutines.runBlocking 9 | 10 | class DeactivateProfile : CliktCommand(name = "deactivate") { 11 | private val profile by profileArgument() 12 | private val cliContext by requireObject() 13 | override fun run(): Unit = runBlocking { 14 | echo(cliContext.sdkClient.deactivate(profile).echoString) 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/kotlin/io/github/legion2/open_cue_cli/profile/ListProfiles.kt: -------------------------------------------------------------------------------- 1 | package io.github.legion2.open_cue_cli.profile 2 | 3 | import com.github.ajalt.clikt.core.CliktCommand 4 | import com.github.ajalt.clikt.core.requireObject 5 | import com.github.ajalt.clikt.parameters.options.flag 6 | import com.github.ajalt.clikt.parameters.options.option 7 | import io.github.legion2.open_cue_cli.CliContext 8 | import io.github.legion2.open_cue_cli.echoString 9 | import io.github.legion2.open_cue_cli.model.echoString 10 | import kotlinx.coroutines.runBlocking 11 | 12 | class ListProfiles : CliktCommand("List all available profiles for the current group sorted by priority", name = "list") { 13 | private val details by option("-d", "--with-details", help = "Show the priority and state of all profiles").flag() 14 | private val activeProfiles by option("-a", "--active", help = "Only list active profiles").flag() 15 | private val cliContext by requireObject() 16 | override fun run() = runBlocking { 17 | val profiles = cliContext.sdkClient.listProfiles().run { 18 | if (activeProfiles) filter { profile -> profile.state } else this 19 | } 20 | echo(profiles.sortedBy { it.priority }.echoString { profile -> if (details) profile.echoString else profile.name }) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/kotlin/io/github/legion2/open_cue_cli/profile/ProfileCommand.kt: -------------------------------------------------------------------------------- 1 | package io.github.legion2.open_cue_cli.profile 2 | 3 | import com.github.ajalt.clikt.core.NoOpCliktCommand 4 | 5 | class ProfileCommand : NoOpCliktCommand(name = "profile") { 6 | override fun aliases(): Map> = mapOf( 7 | "select" to listOf("activate", "-d") 8 | ) 9 | } 10 | -------------------------------------------------------------------------------- /src/main/kotlin/io/github/legion2/open_cue_cli/profile/ProfileInfo.kt: -------------------------------------------------------------------------------- 1 | package io.github.legion2.open_cue_cli.profile 2 | 3 | import com.github.ajalt.clikt.core.CliktCommand 4 | import com.github.ajalt.clikt.core.requireObject 5 | import io.github.legion2.open_cue_cli.CliContext 6 | import io.github.legion2.open_cue_cli.model.echoString 7 | import io.github.legion2.open_cue_cli.profileArgument 8 | import kotlinx.coroutines.runBlocking 9 | 10 | class ProfileInfo : CliktCommand(name = "info") { 11 | private val profile by profileArgument() 12 | private val cliContext by requireObject() 13 | override fun run(): Unit = runBlocking { 14 | echo(cliContext.sdkClient.getProfile(profile).echoString) 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/kotlin/io/github/legion2/open_cue_cli/profile/TriggerProfile.kt: -------------------------------------------------------------------------------- 1 | package io.github.legion2.open_cue_cli.profile 2 | 3 | import com.github.ajalt.clikt.core.CliktCommand 4 | import com.github.ajalt.clikt.core.requireObject 5 | import io.github.legion2.open_cue_cli.CliContext 6 | import io.github.legion2.open_cue_cli.model.echoString 7 | import io.github.legion2.open_cue_cli.profileArgument 8 | import kotlinx.coroutines.runBlocking 9 | 10 | class TriggerProfile : CliktCommand(name = "trigger") { 11 | private val profile by profileArgument(help = "Profile that should be triggered as event") 12 | private val cliContext by requireObject() 13 | override fun run(): Unit = runBlocking { 14 | echo(cliContext.sdkClient.trigger(profile).echoString) 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/kotlin/io/github/legion2/open_cue_cli/sdk/CurrentProfilesDirectoryName.kt: -------------------------------------------------------------------------------- 1 | package io.github.legion2.open_cue_cli.sdk 2 | 3 | import com.github.ajalt.clikt.core.CliktCommand 4 | import com.github.ajalt.clikt.core.requireObject 5 | import io.github.legion2.open_cue_cli.CliContext 6 | import kotlinx.coroutines.runBlocking 7 | 8 | class CurrentProfilesDirectoryName : CliktCommand(name = "profiles-directory-name") { 9 | private val cliContext by requireObject() 10 | override fun run() = runBlocking { 11 | echo(cliContext.sdkClient.currentProfilesDirectoryName()) 12 | } 13 | } -------------------------------------------------------------------------------- /src/main/kotlin/io/github/legion2/open_cue_cli/sdk/DeactivateAllProfiles.kt: -------------------------------------------------------------------------------- 1 | package io.github.legion2.open_cue_cli.sdk 2 | 3 | import com.github.ajalt.clikt.core.CliktCommand 4 | import com.github.ajalt.clikt.core.requireObject 5 | import io.github.legion2.open_cue_cli.CliContext 6 | import kotlinx.coroutines.runBlocking 7 | 8 | class DeactivateAllProfiles : CliktCommand(name = "deactivate-all-profiles") { 9 | private val cliContext by requireObject() 10 | override fun run(): Unit = runBlocking { 11 | cliContext.sdkClient.deactivateAll() 12 | } 13 | } -------------------------------------------------------------------------------- /src/main/kotlin/io/github/legion2/open_cue_cli/sdk/SdkCommand.kt: -------------------------------------------------------------------------------- 1 | package io.github.legion2.open_cue_cli.sdk 2 | 3 | import com.github.ajalt.clikt.core.NoOpCliktCommand 4 | 5 | class SdkCommand : NoOpCliktCommand(name = "sdk") 6 | -------------------------------------------------------------------------------- /src/main/kotlin/io/github/legion2/open_cue_cli/sdk/SdkControl.kt: -------------------------------------------------------------------------------- 1 | package io.github.legion2.open_cue_cli.sdk 2 | 3 | import com.github.ajalt.clikt.core.CliktCommand 4 | import com.github.ajalt.clikt.core.requireObject 5 | import com.github.ajalt.clikt.parameters.options.option 6 | import com.github.ajalt.clikt.parameters.options.switch 7 | import io.github.legion2.open_cue_cli.CliContext 8 | import kotlinx.coroutines.runBlocking 9 | 10 | class SdkControl : CliktCommand(name = "control") { 11 | private val value by option(help = "request or release the control of the sdk").switch("--request" to true, "--release" to false) 12 | private val cliContext by requireObject() 13 | override fun run(): Unit = runBlocking { 14 | val value = value 15 | if (value == null) { 16 | echo(cliContext.sdkClient.getControl()) 17 | } else { 18 | echo(cliContext.sdkClient.setControl(value)) 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /src/main/kotlin/io/github/legion2/open_cue_cli/sdk/SdkInfo.kt: -------------------------------------------------------------------------------- 1 | package io.github.legion2.open_cue_cli.sdk 2 | 3 | import com.github.ajalt.clikt.core.CliktCommand 4 | import com.github.ajalt.clikt.core.requireObject 5 | import io.github.legion2.open_cue_cli.CliContext 6 | import kotlinx.coroutines.runBlocking 7 | 8 | class SdkInfo : CliktCommand(name = "info") { 9 | private val cliContext by requireObject() 10 | override fun run(): Unit = runBlocking { 11 | echo(cliContext.sdkClient.sdkInfo()) 12 | } 13 | } -------------------------------------------------------------------------------- /src/main/kotlin/io/github/legion2/open_cue_cli/sdk/StopAllEvents.kt: -------------------------------------------------------------------------------- 1 | package io.github.legion2.open_cue_cli.sdk 2 | 3 | import com.github.ajalt.clikt.core.CliktCommand 4 | import com.github.ajalt.clikt.core.requireObject 5 | import io.github.legion2.open_cue_cli.CliContext 6 | import kotlinx.coroutines.runBlocking 7 | 8 | class StopAllEvents : CliktCommand(name = "stop-all-events") { 9 | private val cliContext by requireObject() 10 | override fun run(): Unit = runBlocking { 11 | cliContext.sdkClient.clearAllEvents() 12 | } 13 | } --------------------------------------------------------------------------------