chinampa

package module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2024 License: Apache-2.0 Imports: 5 Imported by: 3

README

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)
	}
}

Documentation

Overview

Copyright © 2022 Roberto Hidalgo <[email protected]> SPDX-License-Identifier: Apache-2.0

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute(config Config) error

func Register

func Register(cmds ...*command.Command)

func SetErrorHandler

func SetErrorHandler(handlerFunc func(cmd *cobra.Command, err error) error)

func SetVersionCommandName

func SetVersionCommandName(name string)

Types

type Config

type Config struct {
	Name        string
	Version     string
	Summary     string
	Description string
}

Directories

Path Synopsis
internal
commands
SPDX-License-Identifier: Apache-2.0 Copyright © 2022 Roberto Hidalgo <[email protected]>
SPDX-License-Identifier: Apache-2.0 Copyright © 2022 Roberto Hidalgo <[email protected]>
pkg
env
Package env holds environment variable names that are meant to be overridden by implementations.
Package env holds environment variable names that are meant to be overridden by implementations.
runtime
Package runtime presents environment related information useful during your program's runtime.
Package runtime presents environment related information useful during your program's runtime.
statuscode
package statuscode manages exit codes for programs.
package statuscode manages exit codes for programs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL