The project is organized in the following folders and important files:
cmd/-mainpackages to build executable binaries.docs/- documentation of the project for maintainers and contributors.scripts/- build and release scripts.api/- golang implementation of the Clockify API.pkg/- other packages that support theapior commands.internal/- Go packages that are highly specific to this projectgo.mod- external Go dependencies for this project.Makefile- most of setup and maintenance actions for this project.
All CLI commands will be under pkg/cmd/ and the file naming convention is this:
pkg/cmd/<command>/<subcommand>/<subcommand>.go
Following the same structure as the command path, so clockify-cli client add is at
pkg/cmd/client/add.go, all command packages will have a function named NewCmd<subcommand> that
will receive a cmdutil.Factory type and return a *cobra.Command.
Specific logic for that command must be kept at the same package as it, and all subcommands must be
registered on its parent package. So all subcommands of client will registered on the function
client.NewCmdClient().
Output formatters must stay under the package pkg/output/ using the following
file convention:
pkg/output/<entity>/<format>.go
Shared functionality for printing entities must be at the package
pkg/outpututil/.
Say you will create a new command delete under client.
- Create the package
pkg/cmd/client/delete/ - Create a function called
NewCmdDeleteon a filedelete.go- This function must receive a
cmdutil.Factorystruct and return a*cobra.Commandfully set.
- This function must receive a
- Edit the entity root command at
pkg/cmd/client/client.goto register it as a subcommand using the factory function previously created. If the entity root does not exist yet, then:- Create the file, and in it a function
NewCmdClientthat should receivecmdutil.Factoryand return a*cobra.Commandwith all its subcommands.
- Create the file, and in it a function
- If is the first command of a entity:
- Create a package called
pkg/output/client - Implement output the five basic output formats
table(default),json,quiet(only the ID),template(Go template) andcsv. Each one on a file by itself.
- Create a package called
This document is based on the project-layout.md from github/cli/cli.