Skip to content

plastikfan/maestro

Repository files navigation

🦄 arcadia: Go template for Cobra based cli applications

A B A B A B Go Reference Go report Coverage Status Arcadia Continuous Integration pre-commit A B

🔰 Introduction

This project is a template to aid in the startup of Go cli applications.

📚 Usage

🎀 Features

🔨 Developer Info

By using this template, there is no need to use the cobra-cli to scaffold your application as this has been done already. It should be noted that the structure that is generated by the cobra-cli has been significantly changed in this template, mainly to remove use of the init() function and to minimise use of package level global variables. For a rationale, see go-without-package-scoped-variables.

📝 Checklist of required changes

The following is list of actions that must be performed before using this template. Most of the changes concern changing the name Arcadia to the name of the new application. There are quite a lot of changes required after creating the client project so ideally, there would be a tool the user could run that would automatically apply these changes. Perhaps, this will be developed in the future (either as a golang cli tool or even perhaps implemented as a zsh script using sed/gawk), but for now the user should following the modification steps documented here, which incidently are pretty easy to apply and get right.

As the template is instantiated from github, the new name will automatically replace the top level directory name, that being arcadia.

Assuming the instantiating client project name is maestro and the owning user/org name is pandora...

✅ Rename import statements

  • rename import paths: global search and replace snivilised/arcadia to pandora/maestro

✅ Structural changes

  • github actions workflow: If the client application needs to use github actions for continuous integration, then the name of the workflow needs to be changed. If not, then the workflow file should be deleted

  • remove the dummy code: widget-cmd.go, greeting.go and its associated test greeting_test.go (but only do this once new valid tests are ready to replace it, to avoid references being removed after go mod tidy)

  • replace bootstrap testcase: There is a test case which by default is set to invoke the widget command. When the user is ready to remove this command, then the corresponding test case should be modified to invoke another command with appropriate parameters. This test case is there to ensure that the bootstrapping process works, as opposed to checking the validity of the command itself.

  • review bootstrap.go: this will need to be modified to invoke creation of any custom commands. The execute method of bootstrap should be modified to invoke command builder. Refer to the widget command to see how this is done.

✅ Identifiers

  • change arcadiaTemplData: perform a refactor rename (Rename Symbol) to maestroTemplData

✅ Global search replace arcadia to maestro

Will take case of the following required changes:

  • change module name: update the module name inside the .mod file in the root directory
  • change ApplicationName: modify to reflect the new application name. This application name is incorporated into the name of any translation files to be loaded.
  • update BINARY_NAME: Inside Taskfile.yml, change the value of BINARY_NAME to the name of the client application.
  • update github action workflows: change the name of the workflows in the .yaml files to replace Arcadia to Maestro (note the change of case, if this is important).

✅ Localisation/Internationalisation

  • update translation file: Inside Taskfile.yml, add support for loading any translations that the app will support. By default, it deploys a translation file for en-US so this needs to be updated as appropriate.
  • update message id: This package supports i18n and as part of that defines messages that need to be translated. The user needs to update the message ids of defined messages in messages.go, which by default contain arcadia as part of the id.
  • change the names of the translation files, eg change arcadia.active.en-GB.json to maestro.active.en-GB.json

✅ Github changes

Unfortunately, github doesn't copy over the template project's settings to the client project, so these changes must be made manually:

  • setup branch protection rules: require pull request
  • update project settings: disable Allow merge commits and Allow squash merging

✅ Code coverage

  • coveralls.io: add maestro project

✅ Miscellaneous changes

  • change SOURCE_ID: to "github.com/snivilised/maestro"
  • replace README content
  • update email address in copyright statement: The root.go file contains a placeholder for an email address, update this comment accordingly.
  • create .env file: Add any appropriate secrets to a newly created .env in the root directory and to enable the deploy task to work, define a DEPLOY_TO entry that defines where builds should be deployed to for testing
  • reset version files: this is optional because the release process automatically updates the version number according to the tag specified by the user, but will initially contain the version number which reflects the current value of arcadia at the time the client project is instantiated.
  • install pre-commit hooks: just run pre-commit install

🌐 l10n Translations

This template has been setup to support localisation. The default language is en-GB with support for en-US. There is a translation file for en-US defined as src/internal/l10n/out/arcadia.active.en-US.json.

Make sure that the go-i18n package has been installed so that it can be invoked as cli, see go-i18n for installation instructions.

To maintain localisation of the application, the user must take care to implement all steps to ensure translate-ability of all user facing messages. Whenever there is a need to add/change user facing messages including error messages, to maintain this state, the user must:

  • define template struct (xxxTemplData) in src/internal/l10n/messages.go and corresponding Message() method. All messages are defined here in the same location, simplifying the message extraction process as all extractable strings occur at the same place. Please see go-i18n for all translation/pluralisation options and other regional sensitive content.
  • define a corresponding helper function in src/internal/translate/messages.go. These helper functions are the ones that the rest of the application will use in order to generate region sensitive user facing string content.
  • cd to the l10n at src/internal/l10n/
  • run goi18n extract -format json, this will create an updated active.en.json file
  • run goi18n merge -outdir out -format json active.en.json translate.en-US.json
  • rename out/active.en-US.json to out/arcadia.active.en-US.json. The name arcadia should be changed to the name of the new app (which should correspond with ApplicationName defined in src/app/command/root-cmd.go).

The file out/arcadia.active.en-US.json is the translation file that will be deployed with the executable. Of course, if you want to use a config file format other than json, then there will be a little more work to do, but is fairly straight forward.

🧪 Quick Test

To check the app is working (as opposed to running the unit tests), build and deploy:

task b

task d

NB: the deploy task has been set up for windows by default, but can be changed at will.

Check that the executable and the US language file arcadia.active.en-US.json have both been deployed. Then invoke the widget command with something like

arcadia widget -p "P?<date>" -t 30

Optionally, the user can also specify the directory flag:

arcadia widget -p "P?<date>" -t 30 -d foo-bar.txt

... where foo-bar.txt should be replaced with a file that actually exists.

Since the widget command uses Cobrass option validation to check that the file specified exists, the app will fail if the file does not exist. This serves as an example of how to implement option validation with Cobrass.

About

temp repo to test checklist automation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages