mirror of
https://github.com/vlang/v.git
synced 2025-09-19 12:27:02 -04:00
v.help: add [noreturn]
attribute to print_and_exit
(#19706)
This commit is contained in:
parent
880ce7a33f
commit
1c4c5050de
@ -44,7 +44,6 @@ fn (v1 CheckResult) + (v2 CheckResult) CheckResult {
|
|||||||
fn main() {
|
fn main() {
|
||||||
if non_option_args.len == 0 || '-help' in os.args {
|
if non_option_args.len == 0 || '-help' in os.args {
|
||||||
help.print_and_exit('check-md')
|
help.print_and_exit('check-md')
|
||||||
exit(0)
|
|
||||||
}
|
}
|
||||||
if '-all' in os.args {
|
if '-all' in os.args {
|
||||||
println('´-all´ flag is deprecated. Please use ´v check-md .´ instead.')
|
println('´-all´ flag is deprecated. Please use ´v check-md .´ instead.')
|
||||||
|
@ -89,7 +89,6 @@ fn main() {
|
|||||||
}
|
}
|
||||||
if files.len == 0 || '-help' in args || '--help' in args {
|
if files.len == 0 || '-help' in args || '--help' in args {
|
||||||
help.print_and_exit('fmt')
|
help.print_and_exit('fmt')
|
||||||
exit(0)
|
|
||||||
}
|
}
|
||||||
mut cli_args_no_files := []string{}
|
mut cli_args_no_files := []string{}
|
||||||
for idx, a in os.args {
|
for idx, a in os.args {
|
||||||
|
@ -62,8 +62,7 @@ fn main() {
|
|||||||
options := cmdline.only_options(os.args[1..])
|
options := cmdline.only_options(os.args[1..])
|
||||||
verbose_println('cli params: ${params}')
|
verbose_println('cli params: ${params}')
|
||||||
if params.len < 1 {
|
if params.len < 1 {
|
||||||
vpm_help()
|
help.print_and_exit('vpm', exit_code: 5)
|
||||||
exit(5)
|
|
||||||
}
|
}
|
||||||
vpm_command := params[0]
|
vpm_command := params[0]
|
||||||
mut module_names := params[1..].clone()
|
mut module_names := params[1..].clone()
|
||||||
@ -71,7 +70,7 @@ fn main() {
|
|||||||
// println('module names: ') println(module_names)
|
// println('module names: ') println(module_names)
|
||||||
match vpm_command {
|
match vpm_command {
|
||||||
'help' {
|
'help' {
|
||||||
vpm_help()
|
help.print_and_exit('vpm')
|
||||||
}
|
}
|
||||||
'search' {
|
'search' {
|
||||||
vpm_search(module_names)
|
vpm_search(module_names)
|
||||||
@ -141,7 +140,6 @@ fn vpm_search(keywords []string) {
|
|||||||
search_keys := keywords.map(it.replace('_', '-'))
|
search_keys := keywords.map(it.replace('_', '-'))
|
||||||
if settings.is_help {
|
if settings.is_help {
|
||||||
help.print_and_exit('search')
|
help.print_and_exit('search')
|
||||||
exit(0)
|
|
||||||
}
|
}
|
||||||
if search_keys.len == 0 {
|
if search_keys.len == 0 {
|
||||||
eprintln('´v search´ requires *at least one* keyword.')
|
eprintln('´v search´ requires *at least one* keyword.')
|
||||||
@ -365,7 +363,6 @@ fn vpm_once_filter(module_names []string) []string {
|
|||||||
fn vpm_install(module_names []string, source Source) {
|
fn vpm_install(module_names []string, source Source) {
|
||||||
if settings.is_help {
|
if settings.is_help {
|
||||||
help.print_and_exit('install')
|
help.print_and_exit('install')
|
||||||
exit(0)
|
|
||||||
}
|
}
|
||||||
if module_names.len == 0 {
|
if module_names.len == 0 {
|
||||||
eprintln('´v install´ requires *at least one* module name.')
|
eprintln('´v install´ requires *at least one* module name.')
|
||||||
@ -427,7 +424,6 @@ fn vpm_update(m []string) {
|
|||||||
mut module_names := m.clone()
|
mut module_names := m.clone()
|
||||||
if settings.is_help {
|
if settings.is_help {
|
||||||
help.print_and_exit('update')
|
help.print_and_exit('update')
|
||||||
exit(0)
|
|
||||||
}
|
}
|
||||||
if module_names.len == 0 {
|
if module_names.len == 0 {
|
||||||
module_names = get_installed_modules()
|
module_names = get_installed_modules()
|
||||||
@ -574,7 +570,6 @@ fn vpm_list() {
|
|||||||
fn vpm_remove(module_names []string) {
|
fn vpm_remove(module_names []string) {
|
||||||
if settings.is_help {
|
if settings.is_help {
|
||||||
help.print_and_exit('remove')
|
help.print_and_exit('remove')
|
||||||
exit(0)
|
|
||||||
}
|
}
|
||||||
if module_names.len == 0 {
|
if module_names.len == 0 {
|
||||||
eprintln('´v remove´ requires *at least one* module name.')
|
eprintln('´v remove´ requires *at least one* module name.')
|
||||||
@ -627,10 +622,6 @@ fn ensure_vmodules_dir_exist() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn vpm_help() {
|
|
||||||
help.print_and_exit('vpm')
|
|
||||||
}
|
|
||||||
|
|
||||||
fn vcs_used_in_dir(dir string) ?[]string {
|
fn vcs_used_in_dir(dir string) ?[]string {
|
||||||
mut vcs := []string{}
|
mut vcs := []string{}
|
||||||
for repo_subfolder in supported_vcs_folders {
|
for repo_subfolder in supported_vcs_folders {
|
||||||
|
@ -6,24 +6,23 @@ const help_dir = os.join_path(@VEXEROOT, 'vlib', 'v', 'help')
|
|||||||
|
|
||||||
[params]
|
[params]
|
||||||
pub struct ExitOptions {
|
pub struct ExitOptions {
|
||||||
success_code int // The exit code to use after the specified topic was printed successfully.
|
exit_code int
|
||||||
fail_code int = 1 // The exit code to use after the specified topic could not be printed (e.g., if it is unknown).
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// print_and_exit prints the help topic and exits.
|
// print_and_exit prints the help topic and exits.
|
||||||
pub fn print_and_exit(topic string, exit_opts ExitOptions) {
|
[noreturn]
|
||||||
|
pub fn print_and_exit(topic string, opts ExitOptions) {
|
||||||
if topic == 'topics' {
|
if topic == 'topics' {
|
||||||
print_known_topics()
|
print_known_topics()
|
||||||
exit(exit_opts.success_code)
|
exit(opts.exit_code)
|
||||||
}
|
}
|
||||||
|
fail_code := if opts.exit_code != 0 { opts.exit_code } else { 1 }
|
||||||
for c in topic {
|
for c in topic {
|
||||||
if !c.is_letter() && !c.is_digit() && c != `-` {
|
if !c.is_letter() && !c.is_digit() && c != `-` {
|
||||||
print_topic_unkown(topic)
|
print_topic_unkown(topic)
|
||||||
exit(exit_opts.fail_code)
|
exit(fail_code)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mut topic_path := ''
|
mut topic_path := ''
|
||||||
for path in os.walk_ext(help.help_dir, '.txt') {
|
for path in os.walk_ext(help.help_dir, '.txt') {
|
||||||
if topic == os.file_name(path).all_before('.txt') {
|
if topic == os.file_name(path).all_before('.txt') {
|
||||||
@ -34,14 +33,13 @@ pub fn print_and_exit(topic string, exit_opts ExitOptions) {
|
|||||||
if topic_path == '' {
|
if topic_path == '' {
|
||||||
print_topic_unkown(topic)
|
print_topic_unkown(topic)
|
||||||
print_known_topics()
|
print_known_topics()
|
||||||
exit(exit_opts.fail_code)
|
exit(fail_code)
|
||||||
}
|
}
|
||||||
|
|
||||||
println(os.read_file(topic_path) or {
|
println(os.read_file(topic_path) or {
|
||||||
eprintln('error: failed reading topic file: ${err}')
|
eprintln('error: failed reading topic file: ${err}')
|
||||||
exit(exit_opts.fail_code)
|
exit(fail_code)
|
||||||
})
|
})
|
||||||
exit(exit_opts.success_code)
|
exit(opts.exit_code)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_topic_unkown(topic string) {
|
fn print_topic_unkown(topic string) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user