Skip to content

Commit

Permalink
tools: allow for v download -RD URL/script.vsh, to download `script…
Browse files Browse the repository at this point in the history
….vsh`, then run it locally, then remove it, in a single command
  • Loading branch information
spytheman committed Nov 13, 2024
1 parent 897ec51 commit ee3a182
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cmd/tools/vdownload.v
Original file line number Diff line number Diff line change
Expand Up @@ -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..])
Expand All @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit ee3a182

Please sign in to comment.