cli

package module
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2025 License: MIT Imports: 11 Imported by: 0

README

CLI

Go Reference

Package cli implements a simple command line interface library.

Feature

  • Easy to use.
  • Support IoC.
  • Support nested menus.

Usage

import "gitee.com/erdian718/cli"

func main() {
	app := cli.New("[Application Name]").
		AddService(...).
		AddService(...).
		// ...
		AddService(...)
	app.
		AddMenu(...).
		AddMenu(...).
		// ...
		AddMenu(...)

	if err := app.Run(); err != nil {
		panic(err)
	}
}

Note

  • Do not use this package while using STDIN directly.

Documentation

Overview

Package cli implements a simple command line interface library.

Index

Constants

This section is empty.

Variables

Stdin is the buffer reader of os.Stdin.

Functions

func InputBool added in v0.7.0

func InputBool(prompt string) (bool, error)

InputBool gets bool value from stdin.

func InputComplex64 added in v0.9.0

func InputComplex64(prompt string) (complex64, error)

InputComplex64 gets complex64 value from stdin.

func InputComplex128 added in v0.9.0

func InputComplex128(prompt string) (complex128, error)

InputComplex128 gets complex128 value from stdin.

func InputFloat32 added in v0.9.0

func InputFloat32(prompt string) (float32, error)

InputFloat32 gets float32 value from stdin.

func InputFloat64 added in v0.9.0

func InputFloat64(prompt string) (float64, error)

InputFloat64 gets float64 value from stdin.

func InputInt added in v0.7.0

func InputInt(prompt string) (int, error)

InputInt gets int value from stdin.

func InputInt8 added in v0.9.0

func InputInt8(prompt string) (int8, error)

InputInt8 gets int8 value from stdin.

func InputInt16 added in v0.9.0

func InputInt16(prompt string) (int16, error)

InputInt16 gets int16 value from stdin.

func InputInt32 added in v0.9.0

func InputInt32(prompt string) (int32, error)

InputInt32 gets int32 value from stdin.

func InputInt64 added in v0.9.0

func InputInt64(prompt string) (int64, error)

InputInt64 gets int64 value from stdin.

func InputString added in v0.7.0

func InputString(prompt string) (string, error)

InputString gets string value from stdin.

func InputUint added in v0.9.0

func InputUint(prompt string) (uint, error)

InputUint gets uint value from stdin.

func InputUint8 added in v0.9.0

func InputUint8(prompt string) (uint8, error)

InputUint8 gets uint8 value from stdin.

func InputUint16 added in v0.9.0

func InputUint16(prompt string) (uint16, error)

InputUint16 gets uint16 value from stdin.

func InputUint32 added in v0.9.0

func InputUint32(prompt string) (uint32, error)

InputUint32 gets uint32 value from stdin.

func InputUint64 added in v0.9.0

func InputUint64(prompt string) (uint64, error)

InputUint64 gets uint64 value from stdin.

func Resolve added in v0.5.0

func Resolve[T any](ctx *Context) (T, error)

Resolve resolves the dependencies.

Types

type Application added in v0.5.0

type Application struct {
	Menu
	// contains filtered or unexported fields
}

Application presents a application.

func New added in v0.5.0

func New(name string) *Application

New creates a new application.

func (*Application) AddService added in v0.5.0

func (app *Application) AddService(creator any, shared bool) *Application

AddService adds a service to this application.

func (*Application) Run added in v0.5.0

func (app *Application) Run() error

Run starts the application and waits for it to complete.

func (*Application) SetDivider added in v0.5.0

func (app *Application) SetDivider(divider string) *Application

SetDivider sets divider for this application.

type Context added in v0.5.0

type Context struct {
	context.Context
	// contains filtered or unexported fields
}

Context represents the action context.

func (*Context) Resolve added in v0.9.0

func (ctx *Context) Resolve(values ...any) error

Resolve resolves the dependencies.

func (*Context) ResolveType added in v0.9.0

func (ctx *Context) ResolveType(t reflect.Type) (reflect.Value, error)

ResolveType resolves the dependencies by type.

type Menu struct {
	// contains filtered or unexported fields
}

Menu presents a menu context.

func NewMenu

func NewMenu(name string) *Menu

NewMeun creates a new menu context.

func (m *Menu) AddAction(name string, action func(*Context) error) *Menu

AddAction adds a action to the menu.

func (m *Menu) AddMenu(menu *Menu) *Menu

AddMenu adds a menu to the menu.

Jump to

Keyboard shortcuts

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