adder

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2017 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cmds.Command{
	Subcommands: map[string]*cmds.Command{
		"add": &cmds.Command{
			Arguments: []cmdkit.Argument{
				cmdkit.StringArg("summands", true, true, "values that are supposed to be summed"),
			},
			Run: func(req cmds.Request, re cmds.ResponseEmitter) {
				sum := 0

				for i, str := range req.Arguments() {
					num, err := strconv.Atoi(str)
					if err != nil {
						re.SetError(err, cmdkit.ErrNormal)
						return
					}

					sum += num
					re.Emit(fmt.Sprintf("intermediate result: %d; %d left", sum, len(req.Arguments())-i-1))
				}

				re.Emit(fmt.Sprintf("total: %d", sum))
			},
		},
	},
}

Define the root of the commands

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
remote

Jump to

Keyboard shortcuts

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