Skip to content

Commit

Permalink
vab: add --version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
larpon committed Oct 11, 2024
1 parent 01f76ed commit 5428c4f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions cli/options.v
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub:
clear_device_log bool @[long: 'log-clear'; xdoc: 'Clear the log buffer on the device before deployment.']
// Detected environment
dump_usage bool @[long: 'help'; short: h; xdoc: 'Show this help message and exit']
dump_version bool @[long: 'version'; xdoc: 'Show version information and exit']
list_ndks bool @[xdoc: 'List available NDK versions']
list_apis bool @[xdoc: 'List available API levels']
list_build_tools bool @[xdoc: 'List available Build-tools versions']
Expand Down
7 changes: 5 additions & 2 deletions cli/utils.v
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ fn vab_commit_hash() string {
return hash.trim_space()
}

fn version_full() string {
// version_full returns the version number of this
// executable *including* a git hash if available.
pub fn version_full() string {
return '${exe_version} ${exe_git_hash}'
}

fn version() string {
// version returns the version number found in the nearest `v.mod` file.
pub fn version() string {
mut v := '0.0.0'
vmod := @VMOD_FILE
if vmod.len > 0 {
Expand Down
5 changes: 5 additions & 0 deletions vab.v
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ fn main() {
dump(opt)
}

if opt.dump_version {
println('${cli.exe_short_name} ${cli.version_full()}')
exit(0)
}

if opt.dump_usage {
documentation := flag.to_doc[cli.Options](cli.vab_documentation_config) or {
util.vab_error('Could not generate usage documentation via `flag.to_doc[cli.Options](...)` this should not happen',
Expand Down

0 comments on commit 5428c4f

Please sign in to comment.