dfinity / dfxvm

dfx version manager
Apache License 2.0
7 stars 5 forks source link

refactor: dfxvm command fns return Unit not ExitCode #11

Closed ericswanson-dfinity closed 10 months ago

ericswanson-dfinity commented 10 months ago

Description

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:

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.

How Has This Been Tested?

Refactor covered by existing tests