mirror of
https://github.com/vlang/v.git
synced 2025-09-14 06:52:36 +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
|
retries int
|
||||||
delay time.Duration
|
delay time.Duration
|
||||||
urls []string
|
urls []string
|
||||||
|
should_run bool
|
||||||
|
delete_after_run bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const vexe = os.real_path(os.getenv_opt('VEXE') or { @VEXE })
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
mut ctx := Context{}
|
mut ctx := Context{}
|
||||||
mut fp := flag.new_flag_parser(os.args#[1..])
|
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.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.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.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 {
|
if ctx.show_help {
|
||||||
println(fp.usage())
|
println(fp.usage())
|
||||||
exit(0)
|
exit(0)
|
||||||
|
@ -86,6 +92,15 @@ fn main() {
|
||||||
log.info(' Finished downloading file: ${fpath} .')
|
log.info(' Finished downloading file: ${fpath} .')
|
||||||
log.info(' size: ${fstat.size} bytes')
|
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 {
|
if !ctx.show_sha256 && !ctx.show_sha1 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue