func (c *Config) Label() base.Label {
	return c.label
}
Label to use when extracting code blocks for testing or printing.
package config
import (
	"errors"
	"flag"
	"fmt"
	"os"
	"strconv"
	"time"
	"unicode"
	"github.com/golang/glog"
	"github.com/monopole/mdrip/base"
)
const (
	usageText = `
Extracts code blocks from the given markdown files for further processing.
Modes:
 --mode print  (the default)
   Print extracted code blocks to stdout.
   Use
      eval "$(mdrip file.md)"
   to run in current terminal, impacting your environment.
   Use
      mdrip file.md | source /dev/stdin
   to run in an ephemeral shell that exits with extracted code status.
 --mode test
   To assure that the code blocks in markdown files continue to work,
   a test suite should assert that the following exits with status 0:
     mdrip --mode test --label foo /path/to/markdown
   This extracts code blocks with the label '@foo' from markdown files
   in and below the given directory, and runs them in an mdrip subshell,
   leaving the executing shell unchanged.
   The stdout and stderr of the subprocess are captured, and used to
   report output from failing blocks, facilitating error diagnosis.
   In any other mode, mdrip exits with non-zero status only when used
   incorrectly, e.g. file not found, bad flags, etc.
   In --mode test, mdrip exits with the status of any failing code block.
 --mode demo
   Starts a web server (see --port and --hostname flag) to offer a
   rendered version of the markdown facilitating execution of
   command blocks.
   Key or mouse events copy code blocks to the user's clipboard
   and, if tmux is running, "paste" them to the active tmux window.
 --mode tmux
   Only useful if both a local tmux instance is running, and an mdrip
   is running remotely in '--mode demo'.
   In this mode the first argument to mdrip, normally treated as a
   markdown filename, is treated as a URL.  mdrip attempts to open a
   websocket to that URL.  Discover the URL to use from the help panel
   of the mdrip running in --mode demo.
   When a user clicks on a code block served by mdrip (in --mode demo)
   an attempt is made to find a websocket associated with the user's
   web session.
   If a socket is found, the code block is sent to the socket.  Upon
   receipt, mdrip (in --mode tmux) sends the block to local tmux as if
   the user had typed it.
`
)
type ModeType int
const (
	modeUnknown ModeType = iota
	ModePrint
	ModeTest
	ModeDemo
	ModeTmux
)
var (
	mode = flag.String("mode", "print",
		`Mode is print, test, demo or tmux.`)
	label = flag.String("label", "",
		`Using "--label foo" means extract only blocks annotated with "<!-- @foo -->".`)
	preambled = flag.Int("preambled", 0,
		`In --mode print, run the first {n} blocks in the current shell, and the rest in a trapped subshell.`)
	useHostname = flag.Bool("useHostname", false,
		`In --mode demo, use the hostname utility to specify where to serve, else implicitly use localhost.`)
	port = flag.Int("port", 8000,
		`In --mode demo, expose HTTP at the given port.`)
	blockTimeOut = flag.Duration("blockTimeOut", 1*time.Minute,
		`In --mode test, the max amount of time to wait for a command block to exit.`)
	ignoreTestFailure = flag.Bool("ignoreTestFailure", false,
		`In --mode test, exit with success regardless of extracted code failure.`)
)
type Config struct {
	label      base.Label
	mode       ModeType
	dataSource *base.DataSet
}
func determineMode() ModeType {
	if len(*mode) == 0 {
		return ModePrint
	}
	if len(*mode) < 3 {
		return modeUnknown
	}
	switch unicode.ToLower([]rune(*mode)[2]) {
	case 's':  
		return ModeTest
	case 'm':  
		return ModeDemo
	case 'u':  
		return ModeTmux
	default:
		return ModePrint
	}
}
func determineLabel() base.Label {
	if len(*label) == 0 {
		return base.WildCardLabel
	}
	return base.Label(*label)
}
func (c *Config) BlockTimeOut() time.Duration {
	return *blockTimeOut
}
func (c *Config) Preambled() int {
	return *preambled
}
func (c *Config) HostAndPort() string {
	hostname := ""  
	if *useHostname {
		var err error
		hostname, err = os.Hostname()
		if err != nil {
			glog.Fatalf("Trouble with hostname: %v", err)
		}
	}
	return hostname + ":" + strconv.Itoa(*port)
}
func (c *Config) Mode() ModeType {
	return c.mode
}
func (c *Config) IgnoreTestFailure() bool {
	return *ignoreTestFailure
}