https://github.com/artarts36/singlecli
package for creating single command console application
https://github.com/artarts36/singlecli
cli console console-application framework go
Last synced: about 2 months ago
JSON representation
package for creating single command console application
- Host: GitHub
- URL: https://github.com/artarts36/singlecli
- Owner: ArtARTs36
- License: mit
- Created: 2024-02-22T18:05:57.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-11-20T16:03:14.000Z (over 1 year ago)
- Last Synced: 2024-11-20T17:18:37.485Z (over 1 year ago)
- Topics: cli, console, console-application, framework, go
- Language: Go
- Homepage:
- Size: 48.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# singlecli
singlecli - package for creating single command console application
## App definition
It's simple app for adding numbers
```go
package main
import (
"context"
"fmt"
"strconv"
"time"
cli "github.com/artarts36/singlecli"
)
func main() {
application := cli.App{
BuildInfo: &cli.BuildInfo{
Name: "number-adder",
Version: "0.1.0",
BuildDate: time.Now().String(),
},
Action: run,
Args: []*cli.ArgDefinition{
{
Name: "num1",
Description: "first number",
Required: true,
},
{
Name: "num2",
Description: "second number",
Required: true,
},
},
UsageExamples: []*cli.UsageExample{
{
Command: "number-adder 1 and 2",
},
},
}
application.RunWithGlobalArgs(context.Background())
}
func run(ctx *cli.Context) error {
number1, _ := strconv.Atoi(ctx.GetArg("num1"))
number2, _ := strconv.Atoi(ctx.GetArg("num2"))
fmt.Printf("%d + %d = %d", number1, number2, number1 + number2)
return nil
}
```
## Additional features
### Generate GitHub Action configuration
Run: `go run you_main_file.go --singlecli-codegen-ga`
You also can generate in pipeline with workflow:
```yaml
name: update github action config
permissions: write-all
on:
push:
branches:
- master
jobs:
update-ga-config:
runs-on: ubuntu-latest
steps:
- name: install deps
run: sudo apt install gcc
- name: Check out code
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4 # action page:
with:
go-version: stable
- name: Install Go dependencies
run: go mod download
- name: Configure git user
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
- name: Hash prev version
id: prev_version
run: echo "hash=${{ hashFiles('action.yaml') }}" >> $GITHUB_OUTPUT
- name: Generate new config file
run: |
go run ./cmd/main.go --singlecli-codegen-ga
- name: Commit changes
if: ${{ steps.prev_version.outputs.hash != hashFiles('action.yaml') }}
run: |
git add action.yaml
git commit -m "chore: actualize ga config"
git push
```
## Application examples
* [regexlint - console application for regex validation](https://github.com/ArtARTs36/regexlint)
* [db-exporter - console application for export db schema and data to formats](https://github.com/ArtARTs36/db-exporter)
* [gomodchanger - console tool for changing go module path and imports in code files](https://github.com/ArtARTs36/gomodchanger)
* [telgram-action - action for sending messages to telegram](https://github.com/ArtARTs36/telegram-action)