Created
July 8, 2021 16:40
-
-
Save Flinner/fa424110312de236e24d335d01f8dd97 to your computer and use it in GitHub Desktop.
V coreutils starter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module main | |
import flag | |
import os | |
const ( | |
app_name = 'LeName' | |
app_version = 'v0.0.1' | |
app_description = 'LeName is a starter template' | |
) | |
struct Settings { | |
string_arg string // --flag=something | |
bool_arg bool // --flag | |
} | |
///===================================================================/// | |
/// Main Logic /// | |
///===================================================================/// | |
fn main() { | |
seq(args()) | |
} | |
fn seq(settings Settings) { | |
println('Hello!: settings recieved') | |
println(settings) | |
} | |
///===================================================================/// | |
/// Helper Functions /// | |
///===================================================================/// | |
fn do_help() { | |
println('helping') | |
} | |
///===================================================================/// | |
/// Args /// | |
///===================================================================/// | |
fn args() Settings { | |
mut fp := flag.new_flag_parser(os.args) | |
fp.application(app_name) | |
fp.version(app_version) | |
fp.description(app_description) | |
fp.skip_executable() | |
// need to change this | |
string_arg := fp.string('flag', `f`, 'default value', 'help text here') | |
bool_arg := fp.bool('long-flag', `l`, false, 'help text: this defaults to false') | |
help := fp.bool('help', 0, false, 'display this help and exit') | |
version := fp.bool('version', 0, false, 'output version information and exit') | |
// extra arguments -a -b -c arg1 arg2 arg3 | |
// arg1..3 will be taken | |
// flags used that are not specified will panic | |
fnames := fp.finalize() or { | |
eprintln(err) | |
println(fp.usage()) | |
exit(1) | |
} | |
if help { | |
println(fp.usage()) | |
exit(0) | |
} | |
if version { | |
println('$app_name $app_version') | |
exit(0) | |
} | |
return Settings{string_arg, bool_arg} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment