Skip to content

Commit

Permalink
extra: support install/remove from local sources (#320)
Browse files Browse the repository at this point in the history
* utils: adjust `similarity`, add suggestions from `subcmds`
  • Loading branch information
larpon authored Oct 11, 2024
1 parent 08562dc commit 01f76ed
Show file tree
Hide file tree
Showing 5 changed files with 309 additions and 61 deletions.
38 changes: 38 additions & 0 deletions android/env/env.v
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,44 @@ pub fn install(components string, verbosity int) int {
return 0
}

// remove_components removess various external components installed by `install_components`
// These components can be (TODO: Android SDK components or) extra commands.
pub fn remove_components(arguments []string, verbosity int) ! {
if arguments.len == 0 {
return error('${@FN} requires at least one argument')
}

mut args := arguments.clone()
if args[0] == 'remove' {
args = args[1..].clone() // skip `remove` part
}
if args.len == 0 {
return error('${@FN} requires an argument')
}

components := args[0]
// vab remove extra ...
if components == 'extra' {
if args.len == 1 {
return error('${@FN} extra requires an argument')
}
extra.remove_command(input: args[1..].clone(), verbosity: verbosity) or {
return error('Removing of command failed: ${err}')
}
if verbosity > 0 {
println('Removed successfully')
}
return
}

// TODO: vab remove "x;y;z,i;j;k" (sdkmanager compatible tuple)
// Allows to specify a string list of things to remove
return error('${@FN} TODO: currently `remove` only supports removing extra commands via `vab remove extra ...`')
// if verbosity > 0 {
// println('Removed successfully')
// }
}

// install_components installs various external components that vab can use.
// These components can be Android SDK components or extra commands.
pub fn install_components(arguments []string, verbosity int) ! {
Expand Down
6 changes: 4 additions & 2 deletions cli/cli.v
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ Sub-commands:
doctor Display useful info about your system,
(useful for bug reports)
install Install various components. Example:
`vab install "platforms;android-21"'
`vab install "platforms;android-21"
remove Remove various components. Example:
`vab remove extra github:larpon/vab-sdl'

pub const exe_git_hash = vab_commit_hash()
pub const work_directory = paths.tmp_work()
pub const cache_directory = paths.cache()
pub const rip_vflags = ['-autofree', '-gc', '-g', '-cg', '-prod', 'run', '-showcc', '-skip-unused',
'-no-bounds-checking'] // NOTE this can be removed when the deprecated `cli.args_to_options()` is removed
pub const subcmds = ['complete', 'test-all', 'test-cleancode', 'test-runtime']
pub const subcmds_builtin = ['doctor', 'install']
pub const subcmds_builtin = ['doctor', 'install', 'remove']
pub const accepted_input_files = ['.v', '.apk', '.aab']

pub const vab_env_vars = [
Expand Down
14 changes: 13 additions & 1 deletion cli/utils.v
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,22 @@ pub fn input_suggestions(input string) []string {
$if vab_allow_extra_commands ? {
for extra_alias in extra.installed_aliases() {
similarity := f32(int(strings.levenshtein_distance_percentage(input, extra_alias) * 1000)) / 1000
if similarity > 0.25 {
if similarity > 30 {
suggests << extra_alias
}
}
}
for builtin_command in subcmds_builtin {
similarity := f32(int(strings.levenshtein_distance_percentage(input, builtin_command) * 1000)) / 1000
if similarity > 30 {
suggests << builtin_command
}
}
for sub_command in subcmds {
similarity := f32(int(strings.levenshtein_distance_percentage(input, sub_command) * 1000)) / 1000
if similarity > 30 {
suggests << sub_command
}
}
return suggests
}
Loading

0 comments on commit 01f76ed

Please sign in to comment.