singlecli - package for creating single command console application
It's simple app for adding numbers
package main
import (
"context""fmt""strconv""time"
cli "github.com/artarts36/singlecli"
)
funcmain() {
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())
}
funcrun(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)
returnnil
}Run: go run you_main_file.go --singlecli-codegen-ga
You also can generate in pipeline with workflow:
name: update github action configpermissions: write-allon:
push:
branches:
- masterjobs:
update-ga-config:
runs-on: ubuntu-lateststeps:
- name: install depsrun: sudo apt install gcc
- name: Check out codeuses: actions/checkout@v3
- name: Set up Gouses: actions/setup-go@v4 # action page: <https://github.com/actions/setup-go>with:
go-version: stable
- name: Install Go dependenciesrun: go mod download
- name: Configure git userrun: | git config user.name 'github-actions[bot]' git config user.email 'github-actions[bot]@users.noreply.github.com' - name: Hash prev versionid: prev_versionrun: echo "hash=${{ hashFiles('action.yaml') }}" >> $GITHUB_OUTPUT
- name: Generate new config filerun: | go run ./cmd/main.go --singlecli-codegen-ga - name: Commit changesif: ${{ steps.prev_version.outputs.hash != hashFiles('action.yaml') }}run: | git add action.yaml git commit -m "chore: actualize ga config" git push