tasking

package
v0.0.0-...-104f801 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2014 License: MIT Imports: 7 Imported by: 4

Documentation

Overview

Package tasking provides support for running tasks for gotask. It is intended to be used in concert with the "gotask" command, which runs any function of the form

func TaskXxx(*tasking.T)

where Xxx can be any alphanumeric string (but the first letter must not be in [a-z]) and serves to identify the task name. These TestXxx functions must be declared inside a GOPATH so that gotask can find and compile it.

Task Definition

A task is defined in the form of

// +build gotask

package main

import "github.com/jingweno/gotask/tasking"

// NAME
//    The name of the task - a one-line description of what it does
//
// DESCRIPTION
//    A textual description of the task function
//
// OPTIONS
//    Definition of what command line options it takes
func TaskXxx(t *tasking.T) {
    ...
}

The comments for the task function are parsed as the task's man page by following the man page layout: Section NAME contains the name of the task and a one-line description of what it does, separated by a "-"; Section DESCRIPTION contains the textual description of the task function; Section OPTIONS contains the definition of the command line flags it takes. By default, gotask dasherizes the Xxx part of the task function name and use it as the task name if there's no task name declared in the comment. The gotask build tag constraints task functions to gotask build only. Without the build tag, task functions will be available to application build which may not be desired.

Flags

Flags are declared in section OPTIONS of the task function man page in the comments. The definition of flags should follow the POSIX convention, see http://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html.

For bool flag, the format is

-SHORT-NAME, --LONG-NAME
    DESCRIPTION

For string flag, the format is

-SHORT-NAME, --LONG-NAME=<VALUE>
    DESCRIPTION

If the string flag has a default value, remove the enclosing "<" and ">":

-SHORT-NAME, --LONG-NAME=VALUE
    DESCRIPTION

See https://github.com/jingweno/gotask/tree/master/examples for examples.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Flags

type Flags struct {
	C *cli.Context
}

Flags can be used to retrieve parsed command-line options.

func (Flags) Bool

func (f Flags) Bool(name string) bool

Bool looks up the value of a bool flag, returns false if no bool flag exists

func (Flags) String

func (f Flags) String(name string) string

String looks up the value of a string flag, returns "" if no string flag exists

type T

type T struct {
	Args  []string // command-line arguments
	Flags Flags    // command-line options
	// contains filtered or unexported fields
}

T is a type that is passed through to each task function. T can be used to retrieve context-specific Args and parsed command-line Flags.

func (*T) Error

func (t *T) Error(args ...interface{})

Error is equivalent to Log followed by Fail.

func (*T) Errorf

func (t *T) Errorf(format string, args ...interface{})

Errorf is equivalent to Logf followed by Fail.

func (*T) Exec

func (t *T) Exec(cmd ...string) (err error)

Exec runs the system command. If multiple arguments are given, they're concatenated to one command.

Example:

t.Exec("ls -ltr")
t.Exec("ls", FILE1, FILE2)

func (*T) Fail

func (t *T) Fail()

Fail marks the task as having failed but continues execution.

func (*T) Failed

func (t *T) Failed() bool

Failed checks if the task has failed

func (*T) Fatal

func (t *T) Fatal(args ...interface{})

Fatal is equivalent to Error followed by a call to os.Exit(1).

func (*T) Fatalf

func (t *T) Fatalf(format string, args ...interface{})

Fatalf is equivalent to Errorf followed by a call to os.Exit(1).

func (*T) Log

func (t *T) Log(args ...interface{})

Log formats its arguments using default formatting, analogous to Println.

func (*T) Logf

func (t *T) Logf(format string, args ...interface{})

Logf formats its arguments according to the format, analogous to Printf.

Jump to

Keyboard shortcuts

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