pkg: Refactor cmd module #1
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This implements the following changes and adjustments to the cmd module:
Reduced the amount of global variables to 1. Now the cmd module can either reference a global
runtimeFlagsvariable which contains all the flags passed in from the command line as well as some new helper functions and a helper method for reducing the amount of copy/pasted logic.Implemented a new
GetConfig()function which caches the result of the first lookup as well as cleans up the amount of copy/pasted logic that was otherwise scattered throughout the module.Moved each command's implementation in to named functions to improve future testability as well as allow us to tab over the entire function's logic by one.
Moved the definition of the commotion root directory from the template module in to the cmd module. This now means all directories are now pushed down to the templates module instead of being split between the templates module and the cmd module. Additionally, this will also make it easier to potentially allow re-defining the commotion root directory either via a command line argument or environment variable.
Added a new --repo_url flag to override the git URL that Terraform templates are cloned from. Like above, this means that the templates module now simply clones from the URL passed in instead of attempt to set a default on its own if an empty string or nil is passed in, which should never happen.
Various tweaks to logging. This adjusts certain log statements to run log.Printf instead of calling log.Println(... fmt.Sprintf). The rest of the code and locations these are used will be unified in a follow up patch.