Skip to content

Commit

Permalink
add show command
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodus committed Aug 25, 2019
1 parent d6c2491 commit 368de87
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
31 changes: 28 additions & 3 deletions cmd/main.pony
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use "cli"
use "files"
use "process"

primitive Info
fun version(): String =>
Expand Down Expand Up @@ -72,15 +73,39 @@ actor Main

match command.fullname()
| "ponyup/version" => log.print("ponyup " + Info.version())
| "ponyup/show" => show(log, command)
| "ponyup/show" => show(log, command, auth, prefix)
| "ponyup/update" => sync(log, command, auth, prefix)
else
log.err("Unknown command: " + command.fullname())
log.info(Info.please_report())
end

be show(log: Log, command: Command val) =>
log.info("This currently does absolutely nothing useful.")
be show(log: Log, command: Command val, auth: AmbientAuth, prefix: String) =>
let selected_ponyc_path =
try
_ponyup_dir(auth, prefix)?.join("bin/ponyc")?
else
log.err("invalid path: " + prefix + "/bin/ponyc")
return
end
let ponyc_monitor = ProcessMonitor(
auth,
auth,
object iso is ProcessNotify
fun stdout(p: ProcessMonitor, data: Array[U8] iso) =>
log.print(String.from_iso_array(consume data))

fun failed(p: ProcessMonitor, err: ProcessError) =>
log.err("Unable to execute " + selected_ponyc_path.path)

fun dispose(p: ProcessMonitor, exit: I32) =>
if exit != 0 then failed(p, WaitpidError) end
end,
selected_ponyc_path,
["ponyc"; "--version"],
_env.vars)

ponyc_monitor.done_writing()

be sync(log: Log, command: Command val, auth: AmbientAuth, prefix: String) =>
let source =
Expand Down
3 changes: 3 additions & 0 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ check_file "${prefix}/ponyup/nightly-${latest}/bin/ponyc"
check_file "${prefix}/ponyup/nightly-${latest}/bin/corral"
check_file "${prefix}/ponyup/nightly-${latest}/bin/stable"
check_output "${prefix}/ponyup/bin/ponyc --version" "nightly-${latest}"
check_output "${ponyup_bin} show -v -p=${prefix}" "nightly-${latest}"

test_title "up to date"
check_output "${ponyup_bin} update -v -p=${prefix} nightly-${latest}" \
Expand All @@ -69,10 +70,12 @@ check_file "${prefix}/ponyup/nightly-${latest}/bin/ponyc"
check_file "${prefix}/ponyup/nightly-${latest}/bin/corral"
check_file "${prefix}/ponyup/nightly-${latest}/bin/stable"
check_output "${prefix}/ponyup/bin/ponyc --version" "nightly-${latest}"
check_output "${ponyup_bin} show -v -p=${prefix}" "nightly-${latest}"

test_title "nightly (previous)"
${ponyup_bin} -v -p=${prefix} update nightly-${previous}
check_file "${prefix}/ponyup/nightly-${previous}/bin/ponyc"
check_file "${prefix}/ponyup/nightly-${previous}/bin/corral"
check_file "${prefix}/ponyup/nightly-${previous}/bin/stable"
check_output "${prefix}/ponyup/bin/ponyc --version" "nightly-${previous}"
check_output "${ponyup_bin} show -v -p=${prefix}" "nightly-${previous}"

0 comments on commit 368de87

Please sign in to comment.