Skip to content
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

Use github.com/spf13/cobra module to generate command line interface #70

Merged
merged 4 commits into from
Aug 25, 2021
Merged

Use github.com/spf13/cobra module to generate command line interface #70

merged 4 commits into from
Aug 25, 2021

Conversation

per1234
Copy link
Contributor

@per1234 per1234 commented Aug 20, 2021

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.

@per1234 per1234 added type: enhancement Proposed improvement topic: code Related to content of the project itself labels Aug 20, 2021
internal/cli/root.go Outdated Show resolved Hide resolved
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)
}
Copy link
Contributor

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.
@per1234 per1234 merged commit 8473338 into arduino:main Aug 25, 2021
@per1234 per1234 deleted the cobra branch August 25, 2021 08:22
@per1234 per1234 self-assigned this Nov 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants