a helper to make simple programs with cobra
Go to file
Roberto Hidalgo 4ffa7ba364 add SetOutput to logger for testing convenience 2024-06-19 17:27:47 -06:00
.milpa/commands crazy computers are crazy. go package documentation 2023-03-21 00:28:25 -06:00
internal remove statuscode.RenderHelp 2024-06-19 14:16:10 -06:00
pkg add SetOutput to logger for testing convenience 2024-06-19 17:27:47 -06:00
.editorconfig moar milpa stuff 2022-12-30 23:53:24 -06:00
.gitignore error on unexpected arguments, test out logger, add .milpa 2023-03-20 22:18:09 -06:00
.golangci.yml fix int to string, bump to go 1.21 2024-04-19 23:47:15 -06:00
.tool-versions bump to go 1.22, deps 2024-05-21 00:06:45 -06:00
LICENSE.txt fix license 2022-12-31 00:12:55 -06:00
README.md format readme 2023-01-17 20:48:38 -06:00
go.mod bump to go 1.22, deps 2024-05-21 00:06:45 -06:00
go.sum bump to go 1.22, deps 2024-05-21 00:06:45 -06:00
main.go make version command name adjustable 2023-01-22 22:29:18 -06:00

README.md

Chinampa

Like milpa but for go programs only.

package main

import (
	"os"
	"fmt"

	"git.rob.mx/nidito/chinampa"
	"git.rob.mx/nidito/chinampa/pkg/command"
	"git.rob.mx/nidito/chinampa/pkg/runtime"
	"github.com/sirupsen/logrus"
)


func main() {
	chinampa.Register(&command.Command{
		Path:        []string{"something"},
		Summary:     "does something",
		Description: "a longer description of how it does stuff",
		Arguments: command.Arguments{
			{
				Name:        "argument zero",
				Description: "a help text for using argument zero",
				Required:    true,
			},
		},
		Action: func(cmd *command.Command) error {
			someArg := cmd.Arguments[0].ToValue().(string)

			return fmt.Errorf("Don't know how to do stuff with %s", someArg)
		},
	})

	logrus.SetFormatter(&logrus.TextFormatter{
		DisableLevelTruncation: true,
		DisableTimestamp:       true,
		ForceColors:            runtime.ColorEnabled(),
	})

	if runtime.DebugEnabled() {
		logrus.SetLevel(logrus.DebugLevel)
		logrus.Debug("Debugging enabled")
	}

	cfg := chinampa.Config{
		Name:        "myProgram",
		Version:     "0.0.0",
		Summary:     "a short summary of my program",
		Description: "a longer text describing what its for",
	}

	if err := chinampa.Execute(cfg); err != nil {
		logrus.Errorf("total failure: %s", err)
		os.Exit(2)
	}
}