mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
tools: allow for v download -RD URL/script.vsh
, to download script.vsh
, then run it locally, then remove it, in a single command
This commit is contained in:
parent
897ec51480
commit
ee3a182dfd
1 changed files with 15 additions and 0 deletions
|
@ -16,8 +16,12 @@ mut:
|
|||
retries int
|
||||
delay time.Duration
|
||||
urls []string
|
||||
should_run bool
|
||||
delete_after_run bool
|
||||
}
|
||||
|
||||
const vexe = os.real_path(os.getenv_opt('VEXE') or { @VEXE })
|
||||
|
||||
fn main() {
|
||||
mut ctx := Context{}
|
||||
mut fp := flag.new_flag_parser(os.args#[1..])
|
||||
|
@ -34,6 +38,8 @@ fn main() {
|
|||
ctx.continue_on_failure = fp.bool('continue', `c`, false, 'Continue on download failures. If you download 5 URLs, and several of them fail, continue without error. False by default.')
|
||||
ctx.retries = fp.int('retries', `r`, 10, 'Number of retries, when an URL fails to download.')
|
||||
ctx.delay = time.Duration(u64(fp.float('delay', `d`, 1.0, 'Delay in seconds, after each retry.') * time.second))
|
||||
ctx.should_run = fp.bool('run', `R`, false, 'Run, after the script/program is completely downloaded.')
|
||||
ctx.delete_after_run = fp.bool('delete-after-run', `D`, false, 'Delete the downloaded script/program, after it has been run.')
|
||||
if ctx.show_help {
|
||||
println(fp.usage())
|
||||
exit(0)
|
||||
|
@ -86,6 +92,15 @@ fn main() {
|
|||
log.info(' Finished downloading file: ${fpath} .')
|
||||
log.info(' size: ${fstat.size} bytes')
|
||||
|
||||
if ctx.should_run {
|
||||
run_cmd := '${os.quoted_path(vexe)} run ${os.quoted_path(fpath)}'
|
||||
log.info(' Executing: ${run_cmd}')
|
||||
os.system(run_cmd)
|
||||
}
|
||||
if ctx.delete_after_run {
|
||||
log.info(' Removing: ${fpath}')
|
||||
os.rm(fpath) or {}
|
||||
}
|
||||
if !ctx.show_sha256 && !ctx.show_sha1 {
|
||||
continue
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue