snivilised / tyro

test application for argeno
MIT License
0 stars 0 forks source link

๐Ÿฆ„ 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. As the template is instantiated from github, the new name will automatically replace the top level directory name, that being arcadia.

โž• The following descriptions use owner name pandora and repo name maestro as an example. That is to say the client has instantiated arcadia template into github at url github.com/pandora/maestro

๐Ÿค– Automated changes

Automated via automate-checklist.sh script. When the user instantiates the repo, a github actions workflow is executed which applies changes to the clients repo automatically. The following description describes the changes that are applied on the user's behalf and the workflow is automatically deleted. However, there are other changes that should be made. These compose the manual checklist and should be heeded by the user.

โœ… Rename import statements
โœ… Identifiers
โœ… Global search replace arcadia to maestro

Will take care of the following required changes:

โœ… Localisation/Internationalisation
โœ… Miscellaneous automated changes

๐Ÿ– Manual changes

The following documents manual changes required. Manual checklist:

โ˜‘๏ธ Structural changes

โ˜‘๏ธ Github changes

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

Under Protect matching branches

Of course, its up to the user what settings they use in their repo, these are just recommended as a matter of good practice.

โ˜‘๏ธ Code coverage

โ˜‘๏ธ Miscellaneous changes

๐ŸŒ 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 locale/i18n/deploy/arcadia.active.en-US.json. This is the initial translation for en-US that should be deployed with the app.

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:

For more detailed workflow instructions relating to i18n, please see i18n README

๐Ÿงช Quick Test

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

task tbd

(which performs a test, build then deploy)

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 maestro.active.en-US.json have both been deployed. Then invoke the widget command with something like

maestro widget -p "P?\<date>" -t 30

Optionally, the user can also specify the directory flag:

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

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

This assumes that the the project name is maestro, change as appropriate.

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.