<commit_before>package main

import (
	"fmt"
	"os"

	"github.com/codegangsta/cli"

	"github.com/libopenstorage/openstorage/apiserver"
	osdcli "github.com/libopenstorage/openstorage/cli"
	"github.com/libopenstorage/openstorage/config"
	"github.com/libopenstorage/openstorage/volume"
)

const (
	version = "0.3"
)

func start(c *cli.Context) {

	if !osdcli.DaemonMode(c) {
		cli.ShowAppHelp(c)
	}

	// We are in daemon mode.  Bring up the volume drivers.
	file := c.String("file")
	if file == "" {
		fmt.Println("OSD configuration file not specified.  Visit openstorage.org for an example.")
		return
	}
	cfg, err := config.Parse(file)
	if err != nil {
		fmt.Println(err)
		return
	}

	// Start the volume drivers.
	for d, v := range cfg.Osd.Drivers {

		fmt.Println("Starting volume driver: ", d)
		_, err := volume.New(d, v)
		if err != nil {
			fmt.Println("Unable to start volume driver: ", err)
			return
		}

		err = apiserver.StartDriverAPI(d, 0, config.DriverAPIBase)
		if err != nil {
			fmt.Println("Unable to start volume driver: ", err)
			return
		}

		err = apiserver.StartPluginAPI(d, config.PluginAPIBase)
		if err != nil {
			fmt.Println("Unable to start volume plugin: ", err)
			return
		}
	}

	// Daemon does not exit.
	select {}
}

func main() {
	app := cli.NewApp()
	app.Name = "osd"
	app.Usage = "Open Storage CLI"
	app.Version = version
	app.Flags = []cli.Flag{
		cli.BoolFlag{
			Name:  "json,j",
			Usage: "output in json",
		},
		cli.BoolFlag{
			Name:  osdcli.DaemonAlias,
			Usage: "Start OSD in daemon mode",
		},
		cli.StringSliceFlag{
			Name:  "driver",
			Usage: "driver name and options: name=btrfs,root_vol=/var/openstorage/btrfs",
			Value: new(cli.StringSlice),
		},
		cli.StringFlag{
			Name:  "file,f",
			Usage: "file to read the OSD configuration from.",
			Value: "",
		},
	}
	app.Action = start

	app.Commands = []cli.Command{
		{
			Name:        "driver",
			Aliases:     []string{"d"},
			Usage:       "Manage drivers",
			Subcommands: osdcli.DriverCommands(),
		},
	}

	for _, v := range drivers {
		c := cli.Command{
			Name:        v,
			Aliases:     []string{"v"},
			Usage:       fmt.Sprintf("Manage %s volumes", v),
			Subcommands: osdcli.VolumeCommands(v),
		}
		app.Commands = append(app.Commands, c)
	}
	app.Run(os.Args)
}
<commit_msg>Accept kvdb url on command line, this is required when starting up OSD in daemon mode'<commit_after>package main

import (
	"fmt"
	"net/url"
	"os"

	"github.com/codegangsta/cli"

	"github.com/libopenstorage/kvdb"
	"github.com/libopenstorage/kvdb/etcd"
	"github.com/libopenstorage/kvdb/mem"
	"github.com/libopenstorage/openstorage/apiserver"
	osdcli "github.com/libopenstorage/openstorage/cli"
	"github.com/libopenstorage/openstorage/config"
	"github.com/libopenstorage/openstorage/volume"
)

const (
	version = "0.3"
)

func start(c *cli.Context) {

	if !osdcli.DaemonMode(c) {
		cli.ShowAppHelp(c)
	}

	datastores := []string{mem.Name, etcd.Name}

	// We are in daemon mode.
	file := c.String("file")
	if file == "" {
		fmt.Println("OSD configuration file not specified.  Visit openstorage.org for an example.")
		return
	}
	cfg, err := config.Parse(file)
	if err != nil {
		fmt.Println(err)
		return
	}
	kvdb_url := c.String("kvdb")
	u, err := url.Parse(kvdb_url)

	kv, err := kvdb.New(u.Scheme, "openstorage", []string{u.Path}, nil)
	if err != nil {
		fmt.Println("Failed to initialize KVDB: ", u.Scheme, err)
		fmt.Println("Supported datastores: ", datastores)
		return
	}
	err = kvdb.SetInstance(kv)
	if err != nil {
		fmt.Println("Failed to initialize KVDB: ", err)
		return
	}

	// Start the volume drivers.
	for d, v := range cfg.Osd.Drivers {

		fmt.Println("Starting volume driver: ", d)
		_, err := volume.New(d, v)
		if err != nil {
			fmt.Println("Unable to start volume driver: ", d, err)
			return
		}

		err = apiserver.StartDriverAPI(d, 0, config.DriverAPIBase)
		if err != nil {
			fmt.Println("Unable to start volume driver: ", err)
			return
		}

		err = apiserver.StartPluginAPI(d, config.PluginAPIBase)
		if err != nil {
			fmt.Println("Unable to start volume plugin: ", err)
			return
		}
	}

	// Daemon does not exit.
	select {}
}

func main() {
	app := cli.NewApp()
	app.Name = "osd"
	app.Usage = "Open Storage CLI"
	app.Version = version
	app.Flags = []cli.Flag{
		cli.BoolFlag{
			Name:  "json,j",
			Usage: "output in json",
		},
		cli.BoolFlag{
			Name:  osdcli.DaemonAlias,
			Usage: "Start OSD in daemon mode",
		},
		cli.StringSliceFlag{
			Name:  "driver",
			Usage: "driver name and options: name=btrfs,root_vol=/var/openstorage/btrfs",
			Value: new(cli.StringSlice),
		},
		cli.StringFlag{
			Name:  "kvdb,k",
			Usage: "uri to kvdb e.g. kv-mem://localhost, etcd://localhost:4001",
			Value: "kv-mem://localhost",
		},
		cli.StringFlag{
			Name:  "file,f",
			Usage: "file to read the OSD configuration from.",
			Value: "",
		},
	}
	app.Action = start

	app.Commands = []cli.Command{
		{
			Name:        "driver",
			Aliases:     []string{"d"},
			Usage:       "Manage drivers",
			Subcommands: osdcli.DriverCommands(),
		},
	}

	for _, v := range drivers {
		c := cli.Command{
			Name:        v,
			Aliases:     []string{"v"},
			Usage:       fmt.Sprintf("Manage %s volumes", v),
			Subcommands: osdcli.VolumeCommands(v),
		}
		app.Commands = append(app.Commands, c)
	}
	app.Run(os.Args)
}

{'fraction_non_alphanumeric': 0.1523702031602709, 'fraction_numerical': 0.0018811136192626034, 'mean_word_length': 3.1767478397486255, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1926104', 'n_tokens_mistral': 2190, 'n_tokens_neox': 2006, 'n_words': 461}