diff --git a/command-signatures/json/sdk.json b/command-signatures/json/sdk.json new file mode 100644 index 00000000..99dfb88d --- /dev/null +++ b/command-signatures/json/sdk.json @@ -0,0 +1,284 @@ +{ + "name": "sdk", + "description": "SDKMAN! - The Software Development Kit Manager", + "subcommands": [ + { + "name": [ + "install", + "i" + ], + "description": "Install a candidate version", + "args": [ + { + "name": "candidate", + "description": "SDK candidate to install", + "generatorName": "sdk_candidates" + }, + { + "name": "version", + "description": "Version to install (defaults to latest stable)", + "isOptional": true, + "generatorName": "sdk_versions" + }, + { + "name": "local-path", + "description": "Path to a local installation", + "isOptional": true, + "template": "folders" + } + ] + }, + { + "name": [ + "uninstall", + "rm" + ], + "description": "Uninstall a candidate version", + "args": [ + { + "name": "candidate", + "description": "SDK candidate to uninstall", + "generatorName": "sdk_installed_candidates" + }, + { + "name": "version", + "description": "Version to uninstall", + "generatorName": "sdk_versions" + } + ] + }, + { + "name": [ + "list", + "ls" + ], + "description": "List available candidates or candidate versions", + "args": { + "name": "candidate", + "description": "SDK candidate to list versions for", + "isOptional": true, + "generatorName": "sdk_candidates" + } + }, + { + "name": [ + "use", + "u" + ], + "description": "Use a candidate version in the current shell", + "args": [ + { + "name": "candidate", + "description": "SDK candidate to use", + "generatorName": "sdk_installed_candidates" + }, + { + "name": "version", + "description": "Version to use", + "generatorName": "sdk_versions" + } + ] + }, + { + "name": "config", + "description": "Edit the SDKMAN configuration" + }, + { + "name": [ + "default", + "d" + ], + "description": "Set the default candidate version for all shells", + "args": [ + { + "name": "candidate", + "description": "SDK candidate to set default for", + "generatorName": "sdk_installed_candidates" + }, + { + "name": "version", + "description": "Version to set as default", + "isOptional": true, + "generatorName": "sdk_versions" + } + ] + }, + { + "name": [ + "home", + "h" + ], + "description": "Show the installation path of a candidate version", + "args": [ + { + "name": "candidate", + "description": "SDK candidate", + "generatorName": "sdk_installed_candidates" + }, + { + "name": "version", + "description": "Version to show path for", + "generatorName": "sdk_versions" + } + ] + }, + { + "name": [ + "env", + "e" + ], + "description": "Manage .sdkmanrc environment configuration", + "args": { + "name": "command", + "description": "Env subcommand", + "isOptional": true, + "suggestions": [ + { + "name": "init", + "description": "Initialize a .sdkmanrc file in the current directory", + "type": "subcommand" + }, + { + "name": "install", + "description": "Install SDKs specified in .sdkmanrc", + "type": "subcommand" + }, + { + "name": "clear", + "description": "Reset SDKs to their default versions", + "type": "subcommand" + } + ] + } + }, + { + "name": [ + "current", + "c" + ], + "description": "Display the current version of a candidate or all candidates", + "args": { + "name": "candidate", + "description": "SDK candidate to show current version for", + "isOptional": true, + "generatorName": "sdk_installed_candidates" + } + }, + { + "name": [ + "upgrade", + "ug" + ], + "description": "Show or perform upgrades for candidate versions", + "args": { + "name": "candidate", + "description": "SDK candidate to upgrade", + "isOptional": true, + "generatorName": "sdk_installed_candidates" + } + }, + { + "name": [ + "version", + "v" + ], + "description": "Display the current version of SDKMAN" + }, + { + "name": [ + "broadcast", + "b" + ], + "description": "Display the latest SDK release notifications" + }, + { + "name": "help", + "description": "Show the SDKMAN help message", + "args": { + "name": "subcommand", + "description": "Subcommand to get help for", + "isOptional": true, + "suggestions": [ + "install", + "uninstall", + "list", + "use", + "config", + "default", + "home", + "env", + "current", + "upgrade", + "version", + "broadcast", + "help", + "offline", + "selfupdate", + "update", + "flush" + ] + } + }, + { + "name": "offline", + "description": "Enable or disable offline mode", + "args": { + "name": "mode", + "description": "Enable or disable offline mode", + "isOptional": true, + "suggestions": [ + { + "name": "enable", + "description": "Enable offline mode" + }, + { + "name": "disable", + "description": "Disable offline mode" + } + ] + } + }, + { + "name": "selfupdate", + "description": "Update SDKMAN itself", + "args": { + "name": "force", + "description": "Force re-installation", + "isOptional": true, + "suggestions": [ + { + "name": "force", + "description": "Force re-installation of SDKMAN" + } + ] + } + }, + { + "name": "update", + "description": "Refresh the candidate cache to discover new candidates" + }, + { + "name": "flush", + "description": "Flush SDKMAN local state", + "args": { + "name": "target", + "description": "What to flush", + "isOptional": true, + "suggestions": [ + { + "name": "tmp", + "description": "Flush the temporary folder" + }, + { + "name": "metadata", + "description": "Flush the candidate metadata cache" + }, + { + "name": "version", + "description": "Flush the cached SDKMAN version" + } + ] + } + } + ] +} diff --git a/command-signatures/src/generators/mod.rs b/command-signatures/src/generators/mod.rs index b6100244..aa0ead76 100644 --- a/command-signatures/src/generators/mod.rs +++ b/command-signatures/src/generators/mod.rs @@ -41,6 +41,7 @@ mod powershell; mod pyenv; mod react_native; mod screen; +mod sdk; mod ssh; mod systemctl; mod tar; @@ -98,6 +99,7 @@ pub fn dynamic_command_signature_data() -> HashMap CommandSignatureGenerators { + CommandSignatureGenerators::new("sdk") + .add_generator( + "sdk_candidates", + Generator::script( + CommandBuilder::single_command("cat ~/.sdkman/var/candidates"), + |output| { + output + .trim() + .split(',') + .filter(|s| !s.is_empty()) + .map(|candidate| { + Suggestion::with_description(candidate.trim(), "SDK candidate") + }) + .collect_unordered_results() + }, + ), + ) + .add_generator( + "sdk_installed_candidates", + Generator::script( + CommandBuilder::single_command("ls -1 ~/.sdkman/candidates"), + |output| { + output + .trim() + .lines() + .filter(|s| !s.is_empty()) + .map(|candidate| { + Suggestion::with_description(candidate.trim(), "Installed candidate") + }) + .collect_unordered_results() + }, + ), + ) + .add_generator( + "sdk_versions", + Generator::command_from_tokens( + |tokens, has_trailing_whitespace, _| { + // The candidate name is the token immediately before the version position. + // With trailing whitespace, the last completed token is the candidate. + // Without trailing whitespace, the second-to-last token is the candidate. + let candidate = if has_trailing_whitespace { + tokens.last().copied() + } else { + tokens.get(tokens.len().saturating_sub(2)).copied() + }; + match candidate { + Some(candidate) if !candidate.is_empty() && !candidate.starts_with('-') => { + CommandBuilder::single_command(format!( + "ls -1 ~/.sdkman/candidates/{}/", + candidate + )) + } + _ => CommandBuilder::single_command("echo"), + } + }, + |output| { + output + .trim() + .lines() + .filter(|s| !s.is_empty() && *s != "current") + .map(|version| { + Suggestion::with_description(version.trim(), "Installed version") + }) + .collect_unordered_results() + }, + ), + ) +} diff --git a/package-lock.json b/package-lock.json index c91c6ba1..6eeda26e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -176,6 +176,7 @@ "integrity": "sha512-UOnG6LftzbdaHZcKoPFtOcCKztrQ57WkHDeRD9t/PTQtmT0NHSeWWepj6pS0z/N7+08BHFDQVUrfmfMRcZwbMg==", "dev": true, "license": "MIT", + "peer": true, "bin": { "prettier": "bin/prettier.cjs" },