The top-level methods dfxvm_init::main, dfx::main, and dfxvm::main all return Result<ExitCode, E>.
So do the individual dfxvm command methods: dfxvm::install, dfxvm::update, and so forth. This PR changes their return type to Result<(), E>.
Returning Result<ExitCode, E> allows each top-level command to display some output and return a non-zero exit code, without displaying the output of an Error, all while allowing execution to flow through main.
dfx::main uses this to display messages like this and then exit with a nonzero error code:
error: dfx 0.15.0 is not installed. To install it, run:
error: dfxvm install 0.15.0
The individual dfxvm command methods also follow this call convention. However, they call each other. Examples:
dfxvm default is dfxvm install and then write the new default version
dfxvm update is fetch the latest version number and then set it as default
This means when they call each other the logic would have to be something like this, which is terrible:
let exit_code = install(&version)?;
if exit_code != ExitCode::SUCCESS {
return Ok(exit_code);
}
I don't foresee ll of the dfxvm commands needing to return Ok with any non-zero exit code. This changes their return type to Result<(), T> and moves the ExitCode::SUCCESS return to the cli layer.
Description
The top-level methods
dfxvm_init::main
,dfx::main
, anddfxvm::main
all returnResult<ExitCode, E>
.So do the individual
dfxvm
command methods:dfxvm::install
,dfxvm::update
, and so forth. This PR changes their return type toResult<(), E>
.Returning
Result<ExitCode, E>
allows each top-level command to display some output and return a non-zero exit code, without displaying the output of anError
, all while allowing execution to flow through main.dfx::main
uses this to display messages like this and then exit with a nonzero error code:The individual
dfxvm
command methods also follow this call convention. However, they call each other. Examples:dfxvm default
isdfxvm install
and then write the new default versiondfxvm update
is fetch the latest version number and then set it as defaultThis means when they call each other the logic would have to be something like this, which is terrible:
I don't foresee ll of the
dfxvm
commands needing to return Ok with any non-zero exit code. This changes their return type toResult<(), T>
and moves the ExitCode::SUCCESS return to the cli layer.How Has This Been Tested?
Refactor covered by existing tests