<commit_before>package main

import (
	"fmt"
	"os"
	"time"

	log "github.com/Sirupsen/logrus"
	"github.com/codegangsta/cli"
	"github.com/robinmonjo/dock/notifier"
	"github.com/robinmonjo/dock/port"
	"github.com/robinmonjo/dock/procfs"

	"github.com/robinmonjo/dock/iowire"
	"github.com/robinmonjo/dock/logrotate"
)

var (
	version string //injected by the makefile
)

func main() {
	app := cli.NewApp()
	app.Name = "dock"
	app.Version = fmt.Sprintf("v%s", version)
	app.Author = "<NAME>"
	app.Email = "<EMAIL>"
	app.Usage = "micro init system for containers"

	app.Flags = []cli.Flag{
		cli.StringFlag{Name: "io", Usage: "smart stdin / stdout (see README for more info)"},
		cli.StringFlag{Name: "web-hook", Usage: "hook where process status changes should be notified"},
		cli.StringFlag{Name: "bind-port", Usage: "port the process is expected to bind"},
		cli.IntFlag{Name: "log-rotate", Usage: "duration in hour when stdoud should rotate (if `--io` is a file)"},
		cli.StringFlag{Name: "stdout-prefix", Usage: "add a prefix to stdout lines (format: <prefix>:<color>)"},
		cli.BoolFlag{Name: "debug, d", Usage: "run with verbose output (for developpers)"},
		cli.BoolFlag{Name: "thug", Usage: "translate stopping signals in SIGKILL if process ignore or block the signal"},
	}

	app.Action = func(c *cli.Context) {

		if c.Bool("debug") {
			log.SetLevel(log.DebugLevel)
		}

		exit, err := start(c)
		if err != nil {
			log.Error(err)
		}
		log.Debugf("exit status: %d", exit)
		os.Exit(exit)
	}

	if err := app.Run(os.Args); err != nil {
		log.Fatal(err)
	}
}

func start(c *cli.Context) (int, error) {
	log.Debugf("dock pid: %d", os.Getpid())

	wire, err := iowire.NewWire(c.String("io"))
	if err != nil {
		return 1, err
	}
	defer wire.Close()

	wire.SetPrefix(parsePrefixArg(c.String("stdout-prefix")))

	process := &process{
		argv: c.Args(),
		wire: wire,
	}
	defer process.cleanup()

	sh := newSignalsHandler()
	sh.authority = c.Bool("thug")

	wh := c.String("web-hook")
	notifier.WebHook = wh

	processStateChanged(notifier.StatusStarting)
	defer processStateChanged(notifier.StatusCrashed)

	if err := process.start(); err != nil {
		return exitStatusFromError(err), err
	}

	log.Debugf("process pid: %d", process.pid())<commit_msg>show app help if missing args<commit_after>package main

import (
	"fmt"
	"os"
	"time"

	log "github.com/Sirupsen/logrus"
	"github.com/codegangsta/cli"
	"github.com/robinmonjo/dock/notifier"
	"github.com/robinmonjo/dock/port"
	"github.com/robinmonjo/dock/procfs"

	"github.com/robinmonjo/dock/iowire"
	"github.com/robinmonjo/dock/logrotate"
)

var (
	version string //injected by the makefile
)

func main() {
	app := cli.NewApp()
	app.Name = "dock"
	app.Version = fmt.Sprintf("v%s", version)
	app.Author = "<NAME>"
	app.Email = "<EMAIL>"
	app.Usage = "micro init system for containers"

	app.Flags = []cli.Flag{
		cli.StringFlag{Name: "io", Usage: "smart stdin / stdout (see README for more info)"},
		cli.StringFlag{Name: "web-hook", Usage: "hook where process status changes should be notified"},
		cli.StringFlag{Name: "bind-port", Usage: "port the process is expected to bind"},
		cli.IntFlag{Name: "log-rotate", Usage: "duration in hour when stdoud should rotate (if `--io` is a file)"},
		cli.StringFlag{Name: "stdout-prefix", Usage: "add a prefix to stdout lines (format: <prefix>:<color>)"},
		cli.BoolFlag{Name: "debug, d", Usage: "run with verbose output (for developpers)"},
		cli.BoolFlag{Name: "thug", Usage: "translate stopping signals in SIGKILL if process ignore or block the signal"},
	}

	app.Action = func(c *cli.Context) {

		if c.Bool("debug") {
			log.SetLevel(log.DebugLevel)
		}

		exit, err := start(c)
		if err != nil {
			log.Error(err)
		}
		log.Debugf("exit status: %d", exit)
		os.Exit(exit)
	}

	if err := app.Run(os.Args); err != nil {
		log.Fatal(err)
	}
}

func start(c *cli.Context) (int, error) {
	if len(c.Args()) == 0 {
		cli.ShowAppHelp(c)
		return 0, nil
	}

	log.Debugf("dock pid: %d", os.Getpid())

	wire, err := iowire.NewWire(c.String("io"))
	if err != nil {
		return 1, err
	}
	defer wire.Close()

	wire.SetPrefix(parsePrefixArg(c.String("stdout-prefix")))

	process := &process{
		argv: c.Args(),
		wire: wire,
	}
	defer process.cleanup()

	sh := newSignalsHandler()
	sh.authority = c.Bool("thug")

	wh := c.String("web-hook")
	notifier.WebHook = wh

	processStateChanged(notifier.StatusStarting)
	defer processStateChanged(notifier.StatusCrashed)

	if err := process.start(); err != nil {
		return exitStatusFromError(err), err
	}

	log.Debugf("process pid: %d", process.pid())
{'fraction_non_alphanumeric': 0.16571803852889666, 'fraction_numerical': 0.0008756567425569177, 'mean_word_length': 4.16271186440678, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7066423', 'n_tokens_mistral': 1810, 'n_tokens_neox': 1688, 'n_words': 413}