Skip to content

Commit 01f76ed

Browse files
authored
extra: support install/remove from local sources (vlang#320)
* utils: adjust `similarity`, add suggestions from `subcmds`
1 parent 08562dc commit 01f76ed

File tree

5 files changed

+309
-61
lines changed

5 files changed

+309
-61
lines changed

android/env/env.v

+38
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,44 @@ pub fn install(components string, verbosity int) int {
320320
return 0
321321
}
322322

323+
// remove_components removess various external components installed by `install_components`
324+
// These components can be (TODO: Android SDK components or) extra commands.
325+
pub fn remove_components(arguments []string, verbosity int) ! {
326+
if arguments.len == 0 {
327+
return error('${@FN} requires at least one argument')
328+
}
329+
330+
mut args := arguments.clone()
331+
if args[0] == 'remove' {
332+
args = args[1..].clone() // skip `remove` part
333+
}
334+
if args.len == 0 {
335+
return error('${@FN} requires an argument')
336+
}
337+
338+
components := args[0]
339+
// vab remove extra ...
340+
if components == 'extra' {
341+
if args.len == 1 {
342+
return error('${@FN} extra requires an argument')
343+
}
344+
extra.remove_command(input: args[1..].clone(), verbosity: verbosity) or {
345+
return error('Removing of command failed: ${err}')
346+
}
347+
if verbosity > 0 {
348+
println('Removed successfully')
349+
}
350+
return
351+
}
352+
353+
// TODO: vab remove "x;y;z,i;j;k" (sdkmanager compatible tuple)
354+
// Allows to specify a string list of things to remove
355+
return error('${@FN} TODO: currently `remove` only supports removing extra commands via `vab remove extra ...`')
356+
// if verbosity > 0 {
357+
// println('Removed successfully')
358+
// }
359+
}
360+
323361
// install_components installs various external components that vab can use.
324362
// These components can be Android SDK components or extra commands.
325363
pub fn install_components(arguments []string, verbosity int) ! {

cli/cli.v

+4-2
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,17 @@ Sub-commands:
3030
doctor Display useful info about your system,
3131
(useful for bug reports)
3232
install Install various components. Example:
33-
`vab install "platforms;android-21"'
33+
`vab install "platforms;android-21"
34+
remove Remove various components. Example:
35+
`vab remove extra github:larpon/vab-sdl'
3436

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

4446
pub const vab_env_vars = [

cli/utils.v

+13-1
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,22 @@ pub fn input_suggestions(input string) []string {
5353
$if vab_allow_extra_commands ? {
5454
for extra_alias in extra.installed_aliases() {
5555
similarity := f32(int(strings.levenshtein_distance_percentage(input, extra_alias) * 1000)) / 1000
56-
if similarity > 0.25 {
56+
if similarity > 30 {
5757
suggests << extra_alias
5858
}
5959
}
6060
}
61+
for builtin_command in subcmds_builtin {
62+
similarity := f32(int(strings.levenshtein_distance_percentage(input, builtin_command) * 1000)) / 1000
63+
if similarity > 30 {
64+
suggests << builtin_command
65+
}
66+
}
67+
for sub_command in subcmds {
68+
similarity := f32(int(strings.levenshtein_distance_percentage(input, sub_command) * 1000)) / 1000
69+
if similarity > 30 {
70+
suggests << sub_command
71+
}
72+
}
6173
return suggests
6274
}

0 commit comments

Comments
 (0)