Ejemplo n.º 1
0
// splitFiles converts a comma separated list of files into an array of file names.
func splitFiles(inFiles string) []string {
	files := strings.Split(inFiles, ",")
	for i, f := range files {
		files[i] = strings.Trim(f, " ")
	}

	for _, file := range files {
		if !core.FileExists(file) {
			core.VErrorf("The input file %q does not exist.", file)
			os.Exit(1)
		}
	}

	return files
}
Ejemplo n.º 2
0
// config parses command line arguments and reads from configuration files.
//
// First attempts to read from a configuration file specified at the command
// line. Then tries to read from .service-thumbnails.conf in the user's home
// directory. Then tries reading from /etc/service-thumbnails.conf. Finally
// parses the command line arguments. The command line arguments override
// configuration file values.
func config() *core.Options {
	confCli := ""
	confHome := ""
	confEtc := "/etc/service-thumbnails.conf"
	u, err := user.Current()
	if err == nil {
		confHome = path.Join(u.HomeDir, "/.service-thumbnails.conf")
	}

	/*
		set := flag.NewFlagSet("conf", flag.ContinueOnError)
		set.StringVar(
			&confCli,
			"conf",
			"",
			"Path to configuration file.")
		set.Parse(os.Args[1:])
	*/
	if confCli != "" {
		readConfigFile(confCli, core.Opts)
	} else if core.FileExists(confHome) {
		readConfigFile(confHome, core.Opts)
	} else if core.FileExists(confEtc) {
		readConfigFile(confEtc, core.Opts)
	}

	flag.String(
		"conf",
		"",
		"Path to configuration file.")
	flag.StringVar(
		&core.Opts.Mode,
		"m",
		core.Opts.Mode,
		"Running mode, either 'cli' or 'http'. Defaults to 'cli'.")
	flag.BoolVar(
		&core.Opts.PrintHelp,
		"help",
		core.Opts.PrintHelp,
		"Display command help.")
	flag.BoolVar(
		&core.Opts.PrintVersion,
		"version",
		core.Opts.PrintVersion,
		"Display the app version and quit.")
	flag.BoolVar(
		&core.Opts.Quiet,
		"q",
		core.Opts.Quiet,
		"Run in quiet mode.")
	flag.IntVar(
		&core.Opts.SkipSeconds,
		"s",
		core.Opts.SkipSeconds,
		"Skip this number of seconds into the video before thumbnailing.")
	flag.IntVar(
		&core.Opts.Count,
		"c",
		core.Opts.Count,
		"Number of thumbs to generate in a sprite. 30 is the default.")
	flag.IntVar(
		&core.Opts.Width,
		"w",
		core.Opts.Width,
		"The thumbnail width. Overrides the built in defaults.")
	flag.StringVar(
		&core.Opts.ThumbType,
		"t",
		core.Opts.ThumbType,
		"The type of thumbnail to generate. 'simple' is the default.")
	flag.StringVar(
		&core.Opts.InFile,
		"i",
		core.Opts.InFile,
		"The input video file. Separate multiple files with a comma.")
	flag.StringVar(
		&core.Opts.OutFile,
		"o",
		core.Opts.OutFile,
		"The output image file.")
	flag.StringVar(
		&core.Opts.Host,
		"h",
		core.Opts.Host,
		"The host name to listen on.")
	flag.IntVar(
		&core.Opts.Port,
		"p",
		core.Opts.Port,
		"The port to listen on.")
	flag.Parse()

	return core.Opts
}