Skip to content

πŸ––πŸ‘¨β€πŸ’» Zero dependencies library for building simple commandline apps.

License

Notifications You must be signed in to change notification settings

heartwilltell/scotty

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

21 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

scotty

πŸ––πŸ‘¨β€πŸ’»Scotty - Zero dependencies library to build simple commandline apps.

Basically it is a thin wrapper around standard flag.FlagSet type.

Documentation

Build codecov

Features

  • πŸ€“ Simple API.
  • πŸ‘Œ Zero dependencies.
  • 😘 Plays nice with standard flag package.
  • 😌 Nice default -help information.

Installation

go get github.com/heartwilltell/scotty

Usage

The usage is pretty simple:

  • πŸ‘‰ Declare the root command.
  • πŸ‘‰ Attach subcommands and flags to it.
  • πŸ‘‰ Write your stuff inside the Run function.
  • πŸ‘‰ Call Exec function of the root command somewhere in main function.
package main

import (
	"fmt"
	"log"
	"os"

	"github.com/heartwilltell/scotty"
)

func main() {
	// Declare the root command. 
	rootCmd := scotty.Command{
		Name:  "app",
		Short: "Main command which holds all subcommands",
	}

	// Declare the subcommand.
	subCmd := scotty.Command{
		Name:  "subcommand",
		Short: "Subcommands that does something",
		Run: func(cmd *scotty.Command, args []string) error {
			// Do some your stuff here.
			return nil
		},
	}

	// And here how you bind some flags to your command.
	var logLVL string

	subCmd.Flags().StringVar(&logLVL, "loglevel", "info",
		"set logging level: 'debug', 'info', 'warning', 'error'",
	)

	// Or use the SetFlags function.

	subCmd2 := scotty.Command{
		Name:  "subcommand2",
		Short: "Subcommands that does something",
		SetFlags: func(flags *FlagSet) {
			flags.StringVar(&logLVL, "loglevel", "info",
				"set logging level: 'debug', 'info', 'warning', 'error'",
			)
        },
		Run: func(cmd *scotty.Command, args []string) error {
			// Do some your stuff here.
			return nil
		},
	}

	// Attach subcommand to the root command. 
	rootCmd.AddSubcommands(&subCmd)

	// Execute the root command.
	if err := rootCmd.Exec(); err != nil {
		fmt.Println(err)
		os.Exit(2)
	}
}

License

MIT License.

About

πŸ––πŸ‘¨β€πŸ’» Zero dependencies library for building simple commandline apps.

Topics

Resources

License

Stars

Watchers

Forks

Languages