1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

flag: unify apis

This commit is contained in:
yuyi
2020-03-19 14:06:37 +08:00
committed by GitHub
parent 66639924a4
commit 9ef8499183
8 changed files with 73 additions and 113 deletions

View File

@ -117,7 +117,7 @@ fn main() {
fp.description(app_description)
fp.skip_executable()
show_help:=fp.bool('help', false, 'Show this help screen\n')
show_help:=fp.bool('help', 0, false, 'Show this help screen\n')
flag_options := parse_flags(mut fp)
if( show_help ){ println( fp.usage() ) exit(0) }
@ -181,14 +181,14 @@ pub fn (ws &WebhookServer) reset() {
// parse flags to FlagOptions struct
fn parse_flags(fp mut flag.FlagParser) FlagOptions {
return FlagOptions{
serve : fp.bool('serve', false, 'run in webhook server mode')
work_dir : fp.string('work-dir', work_dir, 'gen_vc working directory')
purge : fp.bool('purge', false, 'force purge the local repositories')
port : fp.int('port', server_port, 'port for web server to listen on')
log_to : fp.string('log-to', log_to, 'log to is \'file\' or \'terminal\'')
log_file : fp.string('log-file', log_file, 'log file to use when log-to is \'file\'')
dry_run : fp.bool('dry-run', dry_run, 'when specified dont push anything to remote repo')
force : fp.bool('force', false, 'force update even if already up to date')
serve : fp.bool('serve', 0, false, 'run in webhook server mode')
work_dir : fp.string('work-dir', 0, work_dir, 'gen_vc working directory')
purge : fp.bool('purge', 0, false, 'force purge the local repositories')
port : fp.int('port', 0, server_port, 'port for web server to listen on')
log_to : fp.string('log-to', 0, log_to, 'log to is \'file\' or \'terminal\'')
log_file : fp.string('log-file', 0, log_file, 'log file to use when log-to is \'file\'')
dry_run : fp.bool('dry-run', 0, dry_run, 'when specified dont push anything to remote repo')
force : fp.bool('force', 0, false, 'force update even if already up to date')
}
}

View File

@ -137,16 +137,16 @@ pub fn (vgit_context mut VGitContext) compile_oldv_if_needed() {
pub fn add_common_tool_options<T>(context mut T, fp mut flag.FlagParser) []string {
tdir := os.temp_dir()
context.workdir = os.realpath(fp.string_('workdir', `w`, tdir, 'A writable base folder. Default: $tdir'))
context.v_repo_url = fp.string('vrepo', vgit.remote_v_repo_url, 'The url of the V repository. You can clone it locally too. See also --vcrepo below.')
context.vc_repo_url = fp.string('vcrepo', vgit.remote_vc_repo_url, 'The url of the vc repository. You can clone it
context.workdir = os.realpath(fp.string('workdir', `w`, tdir, 'A writable base folder. Default: $tdir'))
context.v_repo_url = fp.string('vrepo', 0, vgit.remote_v_repo_url, 'The url of the V repository. You can clone it locally too. See also --vcrepo below.')
context.vc_repo_url = fp.string('vcrepo', 0, vgit.remote_vc_repo_url, 'The url of the vc repository. You can clone it
${flag.SPACE}beforehand, and then just give the local folder
${flag.SPACE}path here. That will eliminate the network ops
${flag.SPACE}done by this tool, which is useful, if you want
${flag.SPACE}to script it/run it in a restrictive vps/docker.
')
context.show_help = fp.bool_('help', `h`, false, 'Show this help screen.')
context.verbose = fp.bool_('verbose', `v`, false, 'Be more verbose.')
context.show_help = fp.bool('help', `h`, false, 'Show this help screen.')
context.verbose = fp.bool('verbose', `v`, false, 'Be more verbose.')
if (context.show_help) {
println(fp.usage())

View File

@ -76,8 +76,8 @@ fn main() {
fp.skip_executable()
fp.limit_free_args(1, 1)
context.cleanup = fp.bool('clean', true, 'Clean before running (slower).')
context.cmd_to_run = fp.string_('command', `c`, '', 'Command to run in the old V repo.\n')
context.cleanup = fp.bool('clean', 0, true, 'Clean before running (slower).')
context.cmd_to_run = fp.string('command', `c`, '', 'Command to run in the old V repo.\n')
commits := vgit.add_common_tool_options(mut context, mut fp)
if commits.len > 0 {

View File

@ -187,8 +187,8 @@ fn main() {
fp.skip_executable()
fp.limit_free_args(1, 2)
context.vflags = fp.string('vflags', '', 'Additional options to pass to the v commands, for example "-cc tcc"')
context.hyperfineopts = fp.string('hyperfine_options', '',
context.vflags = fp.string('vflags', 0, '', 'Additional options to pass to the v commands, for example "-cc tcc"')
context.hyperfineopts = fp.string('hyperfine_options', 0, '',
'Additional options passed to hyperfine.
${flag.SPACE}For example on linux, you may want to pass:
${flag.SPACE}--hyperfine_options "--prepare \'sync; echo 3 | sudo tee /proc/sys/vm/drop_caches\'"

View File

@ -69,9 +69,9 @@ fn main() {
fp.version(tool_version)
fp.description(tool_description)
fp.arguments_description('FILE [FILE]...')
context.show_help = fp.bool_('help', `h`, false, 'Show this help screen.')
context.module_name = fp.string_('module', `m`, 'binary', 'Name of the generated module.\n')
context.prefix = fp.string_('prefix', `p`, '', 'A prefix put before each resource name.\n')
context.show_help = fp.bool('help', `h`, false, 'Show this help screen.')
context.module_name = fp.string('module', `m`, 'binary', 'Name of the generated module.\n')
context.prefix = fp.string('prefix', `p`, '', 'A prefix put before each resource name.\n')
if (context.show_help) {
println(fp.usage())
exit(0)

View File

@ -64,7 +64,7 @@ fn main(){
fp.arguments_description('FILE.v/FOLDER [FILE.v/FOLDER]...')
fp.limit_free_args_to_at_least(1)
fp.skip_executable()
show_help:=fp.bool_('help', `h`, false, 'Show this help screen\n')
show_help:=fp.bool('help', `h`, false, 'Show this help screen\n')
if( show_help ){
println( fp.usage() )
exit(0)