-
-
Notifications
You must be signed in to change notification settings - Fork 3
Use github.com/spf13/cobra
module to generate command line interface
#70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Comment on lines
+91
to
+129
pool := cc.New(4) | ||
worker := func() { | ||
log.Println("Started worker...") | ||
for job := range jobQueue { | ||
buffer := &bytes.Buffer{} | ||
logger := log.New(buffer, "", log.LstdFlags|log.LUTC) | ||
syncLibrary(logger, job.repoMetadata, libraryDb) | ||
|
||
// Output log to file | ||
if err := outputLogFile(logger, job.repoMetadata, buffer); err != nil { | ||
logger.Printf("Error writing log file: %s", err.Error()) | ||
} | ||
|
||
// Output log to stdout | ||
fmt.Println(buffer.String()) | ||
} | ||
log.Println("Completed worker!") | ||
} | ||
pool.Run(worker) | ||
pool.Run(worker) | ||
pool.Run(worker) | ||
pool.Run(worker) | ||
pool.Wait() | ||
|
||
go func() { | ||
id := 0 | ||
for _, repo := range repos { | ||
jobQueue <- &jobContext{ | ||
id: id, | ||
repoMetadata: repo, | ||
} | ||
id++ | ||
} | ||
close(jobQueue) | ||
}() | ||
|
||
for err := range pool.Errors { | ||
feedback.LogError(err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is ok for now since it's best not changing the logic during a refactoring but we must use a more idiomatic way of doing this. And then purge golang-concurrent-workers
completely.
Moving the error logging helper function to a dedicated internal package will make it avaiable for use by any of the module's packages.
Moving the configuration file handling code to a dedicated internal package will make it avaiable for use by any of the module's packages.
The log is used for output during the sync process, but that format is not necessary when the tool is being used directly by a maintainer. These functions will ensure that all the warning and error output displayed during manual processes has a consistent format.
The "command subcommand" command line approach will facilitate the expansion of the tool's command line interface as additional functionality is added. This is provided Cobra, which is the established standard for Arduino tooling Go applications. The previous interface: ``` libraries-repository-engine [CONFIG_FILE [REGISTRY_FILE]] ``` The new interface: ``` libraries-repository-engine sync [--config-file=CONFIG_FILE] [REGISTRY_FILE] ``` Backwards compatibility with the old interface has been preserved, but it is deprecated. A warning will be displayed when it is used.
silvanocerza
approved these changes
Aug 25, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
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.
The "command subcommand" command line approach will facilitate the expansion of the tool's command line interface as
additional functionality is added. This is provided Cobra, which is the established standard for Arduino tooling Go
applications.
The previous interface:
The new interface:
Backwards compatibility with the old interface has been preserved, but it is deprecated. A warning will be displayed when
it is used.