Skip to content

Commit

Permalink
upd: Init gch
Browse files Browse the repository at this point in the history
  • Loading branch information
jtprogru committed Mar 28, 2023
1 parent 72402e9 commit f263052
Show file tree
Hide file tree
Showing 13 changed files with 930 additions and 8 deletions.
29 changes: 29 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: "\U0001F41E Bug Report"
description: File a bug report
title: "[\U0001F41E]: "
labels: ["bug", "triage"]
assignees:
- jtprogru
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this bug report!
- type: textarea
id: what-happened
attributes:
label: What happened?
description: Also tell us, what did you expect to happen?
placeholder: Tell us what you see!
value: "A bug happened!"
validations:
required: true
- type: input
id: version
attributes:
label: Version
description: What version of our software are you running?
placeholder: latest
validations:
required: true

8 changes: 8 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
blank_issues_enabled: false
contact_links:
- name: Telegram Chat
url: https://t.me/jtprogru_chat
about: Please ask and answer questions here.
- name: Bug Reports and Feature Request
url: https://github.com/jtprogru/gch/issues
about: Please report about any bugs and request feature here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "\U0001F680 Feature Request"
description: File a feature Request
title: "[\U0001F680]: "
labels: ["feature", "request"]
assignees:
- jtprogru
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this feature request!
- type: textarea
id: feature-request
attributes:
label: What are you functionality want?
description: Also tell us, what do you lack of functionality?
placeholder: Tell us what you see!
value: "Make a magic!"
validations:
required: true
31 changes: 31 additions & 0 deletions .github/workflows/goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: goreleaser

on:
push:
# run only against tags
tags:
- '*'

permissions:
contents: write
packages: write
issues: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- run: git fetch --force --tags
- uses: actions/setup-go@v4
with:
go-version: stable
- uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@

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

dist/
45 changes: 45 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin

archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of uname.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
# use zip for windows archives
format_overrides:
- goos: windows
format: zip
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'

# The lines beneath this are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
105 changes: 105 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!make
SHELL := /bin/bash
.SILENT:
.DEFAULT_GOAL := help

# Global vars
export SYS_GO=$(shell which go)
export SYS_GOFMT=$(shell which gofmt)

export BINARY_DIR=dist
export BINARY_NAME=gch


.PHONY: run.cmd
## Run as go run main.go
run.cmd: main.go
$(SYS_GO) run main.go

.PHONY: run.bin
## Run as binary
run.bin: build.bin
./$(BINARY_DIR)/$(BINARY_NAME)

.PHONY: tidy
## Install all requirements
tidy: go.mod
$(SYS_GO) mod tidy

.PHONY: build.bin
## Build bin file from go
build.bin: main.go
$(SYS_GO) mod download && CGO_ENABLED=0 $(SYS_GO) build -o ./$(BINARY_DIR)/$(BINARY_NAME) main.go

.PHONY: fmt
## Run go fmt
fmt:
$(SYS_GOFMT) -s -w .

.PHONY: vet
## Run go vet ./...
vet:
$(SYS_GO) vet ./...

.PHONY: clean
## Clean all artifacts
clean:
rm -rf $(BINARY_DIR)

.PHONY: test
## Run all test
test:
go test --short -coverprofile=cover.out -v ./...
make test.coverage

.PHONY: test.coverage
## Run test coverage
test.coverage:
go tool cover -func=cover.out

.PHONY: lint
## Run golangci-lint
lint:
golangci-lint -v run --out-format=colored-line-number

.PHONY: help
## Show this help message
help:
@echo "$$(tput bold)Available rules:$$(tput sgr0)"
@echo
@sed -n -e "/^## / { \
h; \
s/.*//; \
:doc" \
-e "H; \
n; \
s/^## //; \
t doc" \
-e "s/:.*//; \
G; \
s/\\n## /---/; \
s/\\n/ /g; \
p; \
}" ${MAKEFILE_LIST} \
| LC_ALL='C' sort --ignore-case \
| awk -F '---' \
-v ncol=$$(tput cols) \
-v indent=19 \
-v col_on="$$(tput setaf 6)" \
-v col_off="$$(tput sgr0)" \
'{ \
printf "%s%*s%s ", col_on, -indent, $$1, col_off; \
n = split($$2, words, " "); \
line_length = ncol - indent; \
for (i = 1; i <= n; i++) { \
line_length -= length(words[i]) + 1; \
if (line_length <= 0) { \
line_length = ncol - indent - length(words[i]) - 1; \
printf "\n%*s ", -indent, " "; \
} \
printf "%s ", words[i]; \
} \
printf "\n"; \
}' \
| more $(shell test $(shell uname) == Darwin && echo '--no-init --raw-control-chars')

9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
# gch
Go CLI Helper

Go CLI Helper (gch) this is a simple CLI utility that helps make my life easier and will be gradually supplemented with various functionality.

Now gch is not able to do so much, but I use it daily.

## License

MIT
71 changes: 71 additions & 0 deletions cmd/passwd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"fmt"
"math/rand"
"time"

"github.com/spf13/cobra"
)

const (
// lowerLetters is the list of lowercase letters.
lowerLetters = "abcdefghijklmnopqrstuvwxyz"

// upperLetters is the list of uppercase letters.
upperLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

// digits is the list of permitted digits.
digits = "0123456789"

// symbols is the list of symbols.
symbols = "~!@#$%^&*()_+`-={}|[]\\:\"<>?,./"
)

// passwdCmd represents the passwd command
var (
passwdCmd = &cobra.Command{
Use: "passwd",
Short: "Generate random password",
Long: `Simple password generations
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(getPasswd(passwdLength, passwdDigits, passwdSpecials))
},
}
passwdLength int
passwdDigits bool
passwdSpecials bool
r rand.Rand
)

func init() {
rootCmd.AddCommand(passwdCmd)
r = *rand.New(rand.NewSource(time.Now().UnixMicro()))
passwdCmd.Flags().IntVarP(&passwdLength, "length", "l", 24, "Length of password (default=24)")
passwdCmd.Flags().BoolVar(&passwdDigits, "digits", true, "Present digits in password (default=true)")
passwdCmd.Flags().BoolVar(&passwdSpecials, "specials", true, "Present special symbols in password (default=true)")
}

func getPasswd(passwdLen int, digitFlag bool, specFlag bool) string {
var alphabet string
var password string = ""
alphabet = lowerLetters + upperLetters
if digitFlag {
alphabet += digits
}
if specFlag {
alphabet += symbols
}
for i := 0; i < passwdLen; i++ {
password += string(alphabet[r.Intn(len(alphabet))])
}
return password
}
Loading

0 comments on commit f263052

Please sign in to comment.