This is kubectl-plugins repository

golang CLI Template

CircleCI Build status GitHub Actions codecov GoDoc

golang project template for building CLI

Setup

Setup by Command

  1. git clone https://github.com/mpppk/cli-template your_awesome_tool
  2. Replace all strings cli-template in this repository to your_awesome_tool

Setup on GitHub

Click "Use this template" button on GitHub project page.

Project structure

Application layers

  • /cmd includes golang files which implements command and sub commands.
  • /domain includes golang files which implements domain model. This package should not depend on other layers.
  • /handler includes golang files which implements handlers of http request.
  • /usecase includes golang files which implements application use cases. This package is only allowed to depend on domain layer.

Others

  • /util includes golang files which implements utilities. All layers can depend on this package. This package should not depend on other packages.
  • /scripts includes scripts
  • /testdata includes data files for tests. (see https://golang.org/cmd/go/#hdr-Test_packages)

For more detail, see golang-standards/project-layout.

Add new sub command

If you want to create new sub command, Add new go file to /cmd.

For more details, see spf13/cobra.

Task runner

Use Makefile.

Error handling

Use golang.org/x/xerrors.

Documentation

Write godoc(example code) or Example test(example code).

Testing

Don't write test in same package, instead put to package-name_test package.
For example, test of domain/sum.go is in domain_test package, not domain package.
To use unexported variables or functions in test, expose these by export_test.go file.
(ex. /internal/option/root_export_test.go)

For more details, see this article(Japanese).

cmd test

Recommended way is to wrap cobra.Command instance by func (unlike the code generated by cobra add). For example, see cmd/sum_test.go.

with file system

This template depends spf13/afero.
afero.OsFs is used in packages and afero.MemMapFs is used in tests. For example, see cmd/sum_test.go#TestSumWithOutFile

Auto release via Circle CI powered by goreleaser

Create version tag (e.g. v0.0.1) and push to GitHub.
Then goreleaser will release the new version on Circle CI.
(Before push tag, you must provide GitHub token to Circle CI as environment variable)

For more details, see my article (Japanese).

Build & Run Docker image

$ docker build -t cli-template .
...
$ docker run cli-template sum 1 2
3

SaaS integration

Circle CI

This template includes .circleci/config.yml.

AppVeyor

This template includes appveyor.yml.

CodeCov

Makefile includes codecov task which send coverage to CodeCov.
Circle CI also send coverage to CodeCov by its job.

Renovate

This template includes renovate.json.

README template


cli-template

Installation

MacOS

Linux

Download from GitHub Releases

Windows

Download from GitHub Releases

Usage

Write usage of your awesome tool here

Similar Resources

kubetnl tunnels TCP connections from within a Kubernetes cluster to a cluster-external endpoint, e.g. to your local machine. (the perfect complement to kubectl port-forward)

kubetnl kubetnl (kube tunnel) is a command line utility to tunnel TCP connections from within a Kubernetes to a cluster-external endpoint, e.g. to you

Dec 16, 2022

Kubectl plugin to run curl commands against kubernetes pods

kubectl-curl Kubectl plugin to run curl commands against kubernetes pods Motivation Sending http requests to kubernetes pods is unnecessarily complica

Dec 22, 2022

A kubectl plugin for finding decoded secret data with productive search flags.

kubectl-secret-data What is it? This is a kubectl plugin for finding decoded secret data. Since kubectl outputs base64-encoded secrets basically, it m

Dec 2, 2022

A kubectl plugin for getting endoflife information about your cluster.

A kubectl plugin for getting endoflife information about your cluster.

kubectl-endoflife A kubectl plugin that checks your clusters for component compatibility and Kubernetes version end of life. This plugin is meant to a

Jul 21, 2022

A kubectl plugin to evict pods

kubectl-evict A kubectl plugin to evict pods. This plugin is good to remove a pod from your cluster or to test your PodDistruptionBudget. 💿 Installat

Dec 7, 2022

Kubectl Locality Plugin - A plugin to get the locality of pods

Kubectl Locality Plugin - A plugin to get the locality of pods

Nov 18, 2021

kubectl plugin for generating nginx-ingress compatible basic-auth secrets on kubernetes clusters

kubectl-htpasswd kubectl plugin for easily generating hashed basic auth secrets. Supported hash algorithms bcrypt Examples Create the secret on the cl

Jul 17, 2022

🦥 kubectl plugin to easy to view pod

kubectl-lazy Install curl -sSL https://mirror.ghproxy.com/https://raw.githubusercontent.com/togettoyou/kubectl-lazy/main/install.sh | bash Or you can

Oct 13, 2022

The Coherence command line interface (CLI) is a lightweight tool, in the tradition of tools such as kubectl

The Coherence command line interface (CLI) is a lightweight tool, in the tradition of tools such as kubectl

Coherence Command Line Interface (CLI) Contents Overview Why use the Coherence C

Dec 15, 2022
Kubectl golang - kubectl krew template repo

kubectl krew template repo There's a lot of scaffolding needed to set up a good

Jan 11, 2022
Kubernetes plugins for EdgeGallery

Plugins 介绍 the edgegallery plugins repo 软件架构 软件架构说明 安装教程 xxxx xxxx xxxx 使用说明 xxxx xxxx xxxx 参与贡献 Fork 本仓库 新建 Feat_xxx 分支 提交代码 新建 Pull Request 码云特技 使用

Dec 28, 2021
Go Support Code For Writing Falcosecurity Plugins

plugin-sdk-go Go package to facilitate writing Falco/Falco libs plugins. Before using this package, review the developer's guide which fully documents

Sep 20, 2021
Kong Api Gateway Plugins for golang

Prerequisites: Windows Docker. Build Command: docker build -t kong-plugins . Run Command: docker run -ti --rm --name kong-plugins -e "KONG_DATABASE=of

Aug 3, 2022
Installs containerd on Windows, optionally with default CNI plugins

containerd-installer Installs containerd on Windows, optionally with default CNI plugins Usage NAME: containerd-installer.exe - Install containerd

Nov 27, 2022
Kubectl plugin to ease sniffing on kubernetes pods using tcpdump and wireshark
Kubectl plugin to ease sniffing on kubernetes pods using tcpdump and wireshark

ksniff A kubectl plugin that utilize tcpdump and Wireshark to start a remote capture on any pod in your Kubernetes cluster. You get the full power of

Jan 4, 2023
colorizes kubectl output
colorizes kubectl output

kubecolor Colorize your kubectl output get pods describe pods something wrong You can change color theme for light-backgrounded environment What's thi

Jan 8, 2023
kubectl plugin for signing Kubernetes manifest YAML files with sigstore
kubectl plugin for signing Kubernetes manifest YAML files with sigstore

k8s-manifest-sigstore kubectl plugin for signing Kubernetes manifest YAML files with sigstore ⚠️ Still under developement, not ready for production us

Nov 28, 2022
A kubectl plugin for finding decoded secret data with productive search flags.

kubectl-secret-data What is it? This is a kubectl plugin for finding decoded secret data. Since kubectl only outputs base64-encoded secrets, it makes

Dec 2, 2022
A 'kubectl' plugin for interacting with Clusternet.

kubectl-clusternet A kubectl plugin for interacting with Clusternet. Installation Install With Krew kubectl-clusternet can be installed using Krew, pl

Aug 14, 2022