Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
janosmiko committed Feb 2, 2023
0 parents commit 595dee4
Show file tree
Hide file tree
Showing 16 changed files with 1,176 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/funding.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: janosmiko
29 changes: 29 additions & 0 deletions .github/workflows/main-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
name: Reward Greeter Release

on:
push:
tags:
- 'v*'
- '!v*-beta*'

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.19
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}
101 changes: 101 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
### Visual Studio Code
.vscode/**
.history/

### Jetbrains
# User-specific stuff
.idea/**

### Linux
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### Go
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
/dist/**

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work

### Windows
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

### macOS
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

82 changes: 82 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
project_name: reward-greeter
before:
hooks:
- go mod download
- go generate ./...
builds:
- env:
- CGO_ENABLED=0
main: ./cmd/greeter
ldflags:
- -s -w -X main.VERSION={{.Tag}}
goos:
- linux
- windows
- darwin
goarch:
- arm64
- amd64
- "386"
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
format_overrides:
- goos: windows
format: zip
name_template: '{{- .ProjectName -}}_{{- .Os -}}_{{- if and (eq .Os "Linux") (eq .Arch "arm64") -}}aarch64{{- else -}}{{- .Arch -}}{{- end -}}'
files:
- none*
release:
draft: true
replace_existing_draft: true
checksum:
name_template: 'checksums.txt'
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
nfpms:
- package_name: reward-greeter
file_name_template: '{{- .ProjectName -}}_{{- .Os -}}_{{- if and (eq .Os "Linux") (eq .Arch "arm64") -}}aarch64{{- else -}}{{- .Arch -}}{{- end -}}'
replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
maintainer: Janos Miko <[email protected]>
description: Reward-Greeter is a sample plugin for Reward.
license: MIT
formats:
- deb
- rpm
dependencies: [ ]
recommends:
- docker-ce
bindir: /usr/bin
contents: [ ]
rpm:
compression: lzma
brews:
- tap:
owner: rewardenv
name: homebrew-tap
token: "{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}"
name: reward-greeter
commit_author:
name: Janos Miko
email: [email protected]
folder: Formula
description: Reward-Greeter is a sample plugin for Reward.
license: MIT
skip_upload: "false"
dependencies:
- name: reward
type: optional
38 changes: 38 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.DEFAULT_GOAL = help

SHELL = bash
project = reward-greeter
GIT_AUTHOR = janosmiko

help: ## Outputs this help screen
@grep -E '(^[\/a-zA-Z0-9_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}{printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/'

# If the first argument is "gen"...
ifeq (gen,$(firstword $(MAKECMDGOALS)))
# use the rest as arguments for "run"
GEN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
# ...and turn them into do-nothing targets
$(eval $(GEN_ARGS):;@:)
endif

## —— Commands —————————————————————————————————————————————————————————
build: ## Build the command to ./dist
go mod download
go generate ./...
CGO_ENABLED=0 go build -ldflags="-s -w" -o dist/reward-greeter ./cmd/greeter/main.go

package: ## Build the binaries and packages using goreleaser (without releasing it)
goreleaser --clean --snapshot --skip-publish

build-local: ## Build the binaries only using goreleaser (without releasing it)
goreleaser --clean --snapshot --skip-publish

## —— Go Commands —————————————————————————————————————————————————————————
gomod: ## Update Go Dependencies
go mod tidy

lint: ## Lint Go Code
golangci-lint run ./...

test: ## Run Go tests
go test -race -v ./...
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Reward Plugin Template

## Structure

```
.
├── cmd/ # CLI commands
│ ├── greeter/ # The Application's entrypoint. This contains the main.go file.
│ ├── root/ # root command (the top level command)
│ ├── greet/ # greet command
│ └── helpers.go # Helper functions for the CLI commands
├── go.mod
├── go.sum
└── internal/
├── config/ # The app configuration
└── logic/ # The logic of various commands.
# Keeping them in a separate package makes it easier to call one command's logic from another
# and vice-versa.
```

## Running

```console
$ go run cmd/greeter/main.go greet Foo Bar

Hello Foo Bar!
```

## Running in Debug mode

```console
$ DEBUG=true go run cmd/greeter/main.go greet Foo Bar

DEBUG[2023-01-13T18:13:48+01:00] greet.go:12 reward-greeter/internal/logic.(*Client).RunCmdGreet() Creating a greeting...
Hello Foo Bar!
DEBUG[2023-01-13T18:13:48+01:00] greet.go:25 reward-greeter/internal/logic.(*Client).RunCmdGreet() ...greeting created.
```

## Running with Command Line Flags

```console
$ go run cmd/greeter/main.go greet Foo Bar --add-cakes

Hello Foo Bar, here are some cakes 🎂!
```

# Using with Reward

```console
$ go build -o reward-greeter cmd/greeter/main.go
$ mkdir -p ~/.reward/plugins.d
$ mv reward-greeter ~/.reward/plugins.d/

$ reward greeter greet Foo Bar --add-cakes

Hello Foo Bar, here are some cakes 🎂!
```
41 changes: 41 additions & 0 deletions cmd/greet/greet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package greet

import (
"fmt"

"github.com/spf13/cobra"

cmdpkg "github.com/rewardenv/reward-greeter/cmd"
"github.com/rewardenv/reward-greeter/internal/config"
"github.com/rewardenv/reward-greeter/internal/logic"
)

func NewCmdGreet(c *config.Config) *cmdpkg.Command {
var cmd = &cmdpkg.Command{
Command: &cobra.Command{
Use: "greet name",
Short: "greet command description",
Long: `greet command longer description`,
Version: c.AppVersion(),
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) (
[]string, cobra.ShellCompDirective,
) {
return nil, cobra.ShellCompDirectiveNoFileComp
},
RunE: func(cmd *cobra.Command, args []string) error {
err := logic.New(c).RunCmdGreet(cmd, args)
if err != nil {
return fmt.Errorf("error running greet command: %w", err)
}

return nil
},
},
Config: c,
}

cmd.Flags().Bool("add-cakes", false, "enable this flag to add cakes")
c.BindPFlag("add_cakes", cmd.Flags().Lookup("add-cakes"))

return cmd
}
37 changes: 37 additions & 0 deletions cmd/greeter/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright © 2021-2023 JANOS MIKO <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main

import (
"github.com/spf13/cobra"

"github.com/rewardenv/reward-greeter/cmd/root"
"github.com/rewardenv/reward-greeter/internal/config"
)

var (
APPNAME = "reward greeter"
VERSION = "v0.0.1"
)

func main() {
c := config.New(APPNAME, VERSION)
cobra.OnInitialize(func() {
c.Init()
})

root.NewCmdRoot(c).Execute()
}
Loading

0 comments on commit 595dee4

Please sign in to comment.