GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - ArtARTs36/singlecli: package for creating single command console application

BranchesTags
Open more actions menu

Latest commit

 

History

31 Commits
31 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
color
color
 
 
LICENSE
LICENSE
 
 
Makefile
Makefile
 
 
README.md
README.md
 
 
app.go
app.go
 
 
arg.go
arg.go
 
 
arg_queue.go
arg_queue.go
 
 
codegen_cmd.go
codegen_cmd.go
 
 
context.go
context.go
 
 
example.go
example.go
 
 
go.mod
go.mod
 
 
go.sum
go.sum
 
 
help.go
help.go
 
 
input.go
input.go
 
 
opt.go
opt.go
 
 
output.go
output.go
 
 
runner.go
runner.go
 
 
runner_test.go
runner_test.go
 
 
version.go
version.go
 
 

Repository files navigation

singlecli

singlecli - package for creating single command console application

App definition

It's simple app for adding numbers

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:

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: <https://github.com/actions/setup-go>
        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
  • db-exporter - console application for export db schema and data to formats
  • gomodchanger - console tool for changing go module path and imports in code files
  • telgram-action - action for sending messages to telegram

About

package for creating single command console application

Topics

cliconsoleconsole-applicationframeworkgo

Resources

Readme
MIT license
Activity

Stars

0 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.