args

package
v0.29.2 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package args implemets the commandline interface and calls the appropriate commands.

Package args implemets the commandline interface and calls the appropriate commands.

Package args implements the commandline interface and calls the appropriate commands. Its function Handler is called in package main as entry point.

Example (HandlerNone)

func TestShutdown(t *testing.T) {

//defer func() {
//	msg.OsExitAllow(o)
//}()
log.SetFlags(0)
fn := func() {
	o := msg.OsExitDisallow()
	err := Handler([]string{"trice", "sd"})
	if nil != err {
		fmt.Print(err)
	}
	msg.OsExitAllow(o)
}
act := tst.CaptureStdOut(fn)
fmt.Print(act)
s := "Found port:"
assert.Equal(t, s, act[:len(s)])

}

fn := func() {
	err := Handler([]string{"trice"})
	if nil != err {
		fmt.Print(err)
	}
}
act := tst.CaptureStdOut(fn)
fmt.Print(act)
Output:

no args, try: 'trice help'
Example (Help_a)
fn := func() {
	err := Handler([]string{"trice", "help"})
	if nil != err {
		fmt.Print(err)
	}
}
h.Lock()
m.Lock()
act := tst.CaptureStdOut(fn)
m.Unlock()
h.Unlock()
fmt.Print(act)
Output:

syntax: 'trice subcommand' [params]
example 'trice h -help': Print help for help.
Example (Help_b)
fn := func() {
	err := Handler([]string{"trice", "help", "-sd", "-v"})
	if nil != err {
		fmt.Print(err)
	}
}
h.Lock()
m.Lock()
act := tst.CaptureStdOut(fn)
m.Unlock()
h.Unlock()
fmt.Print(act)
Output:

*** https://github.com/rokath/trice ***

If a non-multi parameter is used more than one times the last value wins.
No logfile writing...
syntax: 'trice subcommand' [params]
subcommand 'sd|shutdown': Ends display server at IPA:IPP, works also on a remote mashine.
  -ipa string
    	IP address like '127.0.0.1'.
    	You can specify this swich if you intend to use the remote display option to show the output on a different PC in the network.
    	 (default "localhost")
  -ipp string
    	16 bit IP port number.
    	You can specify this swich if you want to change the used port number for the remote display functionality.
    	 (default "61497")
example: 'trice sd': Shut down remote display server.
No logfile writing...done
Example (Log)
fn := func() {
	m.Lock()
	err := Handler([]string{"trice", "log", "-p", "COMX"})
	m.Unlock()
	if nil != err {
		fmt.Print(err)
	}
}
act := tst.CaptureStdOut(fn)
fmt.Print(act)
Output:

can not open COMX
Example (Refresh)
fn := func() {
	m.Lock()
	err := Handler([]string{"trice", "refresh"})
	m.Unlock()
	if nil != err {
		fmt.Print(err)
	}
}
act := tst.CaptureStdOut(fn)
fmt.Print(act)
Output:

Example (Renew)
fn := func() {
	m.Lock()
	err := Handler([]string{"trice", "renew"})
	m.Unlock()
	if nil != err {
		fmt.Print(err)
	}
}
act := tst.CaptureStdOut(fn)
fmt.Print(act)
Output:

Example (Update)
fn := func() {
	m.Lock()
	err := Handler([]string{"trice", "update"})
	m.Unlock()
	if nil != err {
		fmt.Print(err)
	}
}
act := tst.CaptureStdOut(fn)
fmt.Print(act)
Output:

Example (WrongSubcommand)
fn := func() {
	err := Handler([]string{"trice", "xyz"})
	if nil != err {
		fmt.Print(err)
	}
}
act := tst.CaptureStdOut(fn)
fmt.Print(act)
Output:

unknown subcommand 'xyz'. try: 'trice help|h'

Index

Examples

Constants

View Source
const DefaultPrefix = "source: "

Variables

View Source
var (
	// Version is the program version number and is injected from main package.
	Version string

	// Commit is the program checksum and injected from main package.
	Commit string

	// Date is the compile time and injected from main package.
	Date string
)

Functions

func Handler

func Handler(args []string) error

Handler is called in main, evaluates args and calls the appropriate functions. It returns for program exit.

Types

This section is empty.

Jump to

Keyboard shortcuts

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