Skip to content

Commit bca5896

Browse files
committed
feat: init
0 parents  commit bca5896

30 files changed

+780
-0
lines changed

.env.example

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
APP_ENV=development

.github/workflows/main.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
name: "Custom Action test"
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
permissions:
8+
contents: read
9+
packages: read
10+
jobs:
11+
build:
12+
timeout-minutes: 15
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
- uses: actions/setup-go@v4
17+
with:
18+
go-version-file: "./go.mod"
19+
- name: go mod download
20+
run: |
21+
go mod download
22+
mv .env.example .env
23+
- name: replace APP_ENV
24+
uses: ./
25+
with:
26+
envPath: .env
27+
commands: |
28+
version
29+
set -k APP_ENV test
30+
list --json
31+
- name: go test
32+
run: go test ./...

.github/workflows/release.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
name: "release ennbu"
3+
on:
4+
push:
5+
tags:
6+
- "v[0-9]+.[0-9]+.[0-9]+"
7+
permissions:
8+
contents: write
9+
packages: write
10+
issues: write
11+
concurrency:
12+
group: ${{ github.workflow }}
13+
cancel-in-progress: true
14+
jobs:
15+
releases:
16+
timeout-minutes: 20
17+
name: Release Go Binary
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v3
21+
with:
22+
fetch-depth: 0
23+
- uses: actions/setup-go@v4
24+
with:
25+
go-version-file: "./go.mod"
26+
- uses: docker/[email protected]
27+
with:
28+
registry: ghcr.io
29+
username: u-yas
30+
password: ${{ secrets.GITHUB_TOKEN }}
31+
- uses: goreleaser/[email protected]
32+
with:
33+
version: latest
34+
args: release --clean
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
13+
14+
# Dependency directories (remove the comment below to include it)
15+
# vendor/
16+
17+
# binary
18+
ennbu
19+
20+
# test .env file
21+
.env*
22+
!.env.example
23+
24+
dist/

.golangci.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Options for analysis running.
2+
run:
3+
concurrency: 8
4+
timeout: 5m
5+
issues-exit-code: 1
6+
tests: true
7+
skip-dirs-use-default: false
8+
allow-parallel-runners: true

.goreleaser.yaml

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# This is an example .goreleaser.yml file with some sensible defaults.
2+
# Make sure to check the documentation at https://goreleaser.com
3+
before:
4+
hooks:
5+
# You may remove this if you don't use go modules.
6+
- go mod tidy
7+
8+
builds:
9+
- env:
10+
- CGO_ENABLED=0
11+
goos:
12+
- linux
13+
- windows
14+
- darwin
15+
ldflags:
16+
- -X github.com/u-yas/ennbu/cmd.version={{.Version}}
17+
main: ./main.go
18+
binary: ennbu
19+
goarch:
20+
- amd64
21+
- arm64
22+
archives:
23+
- format: tar.gz
24+
name_template: >-
25+
{{ .ProjectName }}_
26+
{{- tolower title .Os }}_
27+
{{- if eq .Arch "amd64" }}x86_64
28+
{{- else if eq .Arch "386" }}i386
29+
{{- else }}{{ .Arch }}{{ end }}
30+
{{- if .Arm }}v{{ .Arm }}{{ end }}
31+
format_overrides:
32+
- goos: windows
33+
format: zip
34+
checksum:
35+
name_template: 'checksums.txt'
36+
snapshot:
37+
name_template: "{{ incpatch .Version }}-next"
38+
changelog:
39+
sort: asc
40+
filters:
41+
exclude:
42+
- '^docs:'
43+
- '^test:'
44+
dockers:
45+
46+
- image_templates: ["ghcr.io/u-yas/ennbu:{{ .Version }}","ghcr.io/u-yas/ennbu:latest"]
47+
goos: linux
48+
goarch: amd64
49+
dockerfile: Dockerfile.release
50+
build_flag_templates:
51+
- "--pull"
52+
- "--label=org.opencontainers.image.created={{.Date}}"
53+
- "--label=org.opencontainers.image.name={{.ProjectName}}"
54+
- "--label=org.opencontainers.image.revision={{.Commit}}"
55+
- "--label=org.opencontainers.image.version={{.Version}}"
56+
- "--label=org.opencontainers.image.url=https://github.com/u-yas/ennbu"
57+
- "--label=org.label-schema.schema-version=1.0"
58+
- "--label=org.label-schema.name={{.ProjectName}}"
59+
- "--label=org.label-schema.url=https://github.com/u-yas/ennbu"
60+
- "--label=org.label-schema.version={{.Version}}"
61+
- "--label=org.label-schema.build-date={{.Date}}"

Dockerfile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM golang:1.20.2-bullseye AS builder
2+
3+
WORKDIR /work
4+
5+
COPY go.mod go.sum ./
6+
RUN go mod download
7+
8+
COPY . .
9+
10+
RUN CGO_ENABLED=0 go build -o /ennbu
11+
12+
FROM debian:bullseye-slim
13+
COPY --from=builder /ennbu /usr/bin/ennbu
14+
COPY entrypoint.sh /entrypoint.sh
15+
16+
ENTRYPOINT ["/entrypoint.sh"]

Dockerfile.release

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM debian:bullseye-slim
2+
# ARG VERSION
3+
WORKDIR /
4+
COPY ennbu /usr/bin/ennbu
5+
6+
ENTRYPOINT ["/usr/bin/ennbu"]

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 inuneko
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
2+
# ennbu - .env Editor CLI
3+
4+
`ennbu` is a command-line interface (CLI) tool for managing .env files in your projects, written in Go. It allows you to easily set, replace, list, and get values of keys within your .env files.
5+
6+
## Features
7+
8+
- Get a specific key-value pair from a .env file
9+
- List all key-value pairs in a .env file
10+
- Set a new value for a key in a .env file, creating the key if it doesn't exist
11+
- Replace a value for an existing key in a .env file
12+
13+
## Installation
14+
15+
There are several ways to install ennbu:
16+
17+
1. Using Go
18+
To install ennbu with Go, make sure you have Go installed on your system, and then run:
19+
20+
```bash
21+
go install github.com/u-yas/ennbu@latest
22+
```
23+
24+
2. Downloading [from GitHub Releases](https://github.com/u-yas/ennbu/releases)
25+
26+
```bash
27+
curl -L -o ennbu https://github.com/u-yas/ennbu/releases/download/v0.0.1/ennbu-linux-x86_64.tar.gz
28+
sudo mv ennbu /usr/local/bin/
29+
```
30+
31+
3. Using Docker
32+
33+
```bash
34+
docker run -it -v "$(pwd):/workdir" ghcr.io/u-yas/ennbu:latest <command>
35+
```
36+
37+
4. Github Action
38+
39+
```yml
40+
---
41+
name: "golang testing"
42+
on:
43+
pull_request:
44+
branches:
45+
- main
46+
jobs:
47+
build:
48+
timeout-minutes: 15
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@v3
52+
- uses: actions/setup-go@v4
53+
with:
54+
go-version-file: "./go.mod"
55+
- name: go mod download
56+
run: go mod download
57+
- name: replace APP_ENV
58+
uses: u-yas/[email protected]
59+
with:
60+
envPath: .env
61+
commands: |
62+
set -k APP_ENV test
63+
list --json
64+
- name: go test
65+
run: go test ./...
66+
67+
```
68+
69+
### Usage
70+
71+
#### Get
72+
73+
To get the value of a specific key in a .env file, use the `get` command:
74+
75+
```bash
76+
ennbu get -k KEY_NAME -e .env
77+
```
78+
79+
#### List
80+
81+
To list all key-value pairs in a .env file, use the `list` command:
82+
83+
```bash
84+
ennbu list -e .env
85+
```
86+
87+
To list the key-value pairs in JSON format, use the `--json` flag:
88+
89+
```bash
90+
ennbu list --json -e .env
91+
```
92+
93+
#### Set
94+
95+
To set a new value for a key in a .env file, use the `set` command:
96+
97+
```bash
98+
ennbu set -k KEY_NAME -v VALUE -e .env
99+
```
100+
101+
#### Replace
102+
103+
To replace a value for an existing key in a .env file, use the `replace` command:
104+
105+
echo NEW_VALUE | ennbu replace -k KEY_NAME -e .env
106+
107+
## Contributing
108+
109+
Contributions are welcome! Please feel free to submit a [pull request](https://github.com/u-yas/ennbu/pulls) or [open an issue.](https://github.com/u-yas/ennbu/issues/new)

action.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
name: 'Run ennbu'
3+
description: 'GitHub Action for ennbu, a tool edit .env file'
4+
branding:
5+
icon: 'octagon'
6+
color: 'gray-dark'
7+
inputs:
8+
commands:
9+
description: ennbu subcommands
10+
required: true
11+
envPath:
12+
description: .env file path
13+
required: true
14+
runs:
15+
using: 'docker'
16+
image: 'Dockerfile'

aqua.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
# aqua - Declarative CLI Version Manager
3+
# https://aquaproj.github.io/
4+
# checksum:
5+
# enabled: true
6+
# require_checksum: true
7+
# supported_envs:
8+
# - all
9+
registries:
10+
- type: standard
11+
ref: v3.149.0 # renovate: depName=aquaproj/aqua-registry
12+
packages:
13+
- name: golangci/[email protected]
14+
- name: hadolint/[email protected]
15+
- name: rhysd/[email protected]
16+
- name: evilmartians/[email protected]

cmd/get.go

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
Copyright © 2023 u-yas <[email protected]>
3+
*/
4+
package cmd
5+
6+
import (
7+
"github.com/MakeNowJust/heredoc/v2"
8+
"github.com/spf13/cobra"
9+
"github.com/u-yas/ennbu/flags"
10+
"github.com/u-yas/ennbu/get"
11+
)
12+
13+
// getCmd represents the get command
14+
var getCmd = &cobra.Command{
15+
Use: "get",
16+
Short: "Get the value of a specified key in .env file",
17+
Example: heredoc.Doc(`
18+
$ ennbu get KEY
19+
$ ennbu get -e .env.development
20+
`),
21+
RunE: get.Run,
22+
}
23+
24+
func init() {
25+
_ = getCmd.MarkFlagRequired(flags.FlagKey)
26+
27+
rootCmd.AddCommand(getCmd)
28+
}

0 commit comments

Comments
 (0)