Skip to content

nasoooor29/ExportIT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ExportIt

What is this?

Just write your function, and you'll have a CLI tool-no need to worry about flags, figuring out their names, or creating a config struct to manage them. Simply focus on the function, and let me take care of the rest.

Usage

  1. create your functions
func Curl(link string) (string, error) {
	res, err := http.Get(link)
	if err != nil {
		return "", err
	}
	defer res.Body.Close()
	data, err := io.ReadAll(res.Body)
	if err != nil {
		return "", err
	}
	return string(data), nil
}

func Cat(path string) (string, error) {
	data, err := os.ReadFile(path)
	if err != nil {
		return "", err
	}
	fmt.Println(string(data))
	return string(data), nil
}
  1. use the tool
import (
	"fmt"
	"io"
	"net/http"
	"os"

	"github.com/nasoooor29/ExportIT"
)

func main() {
	ExportIT.ExecCli(
		"appName",
		"short Desc",
		"Long Description",
		ExportIT.CliNamedParam(Curl),
		ExportIT.CliNamedParam(Cat),
	)
}
  1. you are done!!
❯ go build
❯ ./ExportIT
Long Description

Usage:
  appName [command]

Available Commands:
  Cat         main.Cat
  Curl        main.Curl
  completion  Generate the autocompletion script for the specified shell
  help        Help about any command

Flags:
  -h, --help   help for appName

Use "appName [command] --help" for more information about a command.
❯ 

what is the catch?

  • currently it work only with simple data types - string - int - bool
  • currently only work with named arguments
  • can't pipe things into it

todos:

  • better shorthand naming
  • cli for init sample
  • arg first uppercase rune means required cli arg
  • add positional args function
  • instead of pos args func [FIRST LETTER for req]whateverTheArg[P0S] example "UrlP0S"

About

Don't write or configure flags ever again

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages