func main()

in cmd/cli/main.go [33:104]


func main() {
	app := cli.NewApp()
	app.Name = "Bundle Helper"
	app.Usage = "Extracts a bundle and prints the command to source the bundle into a shell environment. " +
		"Will intelligently cache in the cache directory."
	app.Flags = []cli.Flag{
		cli.StringFlag{Name: "bundle", Value: "", Usage: "Path to bundle file"},
		cli.StringFlag{Name: "prefix", Value: "", Usage: "Prefix to put onto the source command"},
		cli.StringFlag{Name: "cache", Value: "cache", Usage: "Folder to be used as the cache " +
			"directory for extracted bundles."},
	}

	local := local.NewStreamer()
	stream.RegisterStreamer(local)

	app.Action = func(c *cli.Context) error {
		cachePath := c.String("cache")
		if _, err := os.Stat(cachePath); os.IsNotExist(err) {
			err = os.Mkdir(cachePath, os.ModePerm)
			if err != nil {
				fmt.Printf("Failed to create cache directory: %s", cachePath)
				log.Fatal(err)
				return err
			}
		}
		bundleStore := store.NewSimpleStore(cachePath)

		bundlePath := c.String("bundle")
		if bundlePath == "" {
			fmt.Println("Bundle path cannot be empty.")
			return errors.New("bundle path cannot be empty")
		}
		absBundlePath, err := filepath.Abs(bundlePath)
		if err != nil {
			fmt.Printf("Bundle path is invalid: %s", bundlePath)
			log.Fatal(err)
			return err
		}
		prefixPath := c.String("prefix")

		files, err := ioutil.ReadDir(cachePath)
		if err != nil {
			log.Fatal(err)
		}

		var keys []string
		for _, file := range files {
			if file.IsDir() {
				keys = append(keys, file.Name())
			}
		}

		err = bundleStore.Load(keys)
		if err != nil {
			log.Fatal(err)
			return err
		}

		bundleProvider := bundle.NewProvider(bundleStore)
		b, err := bundleProvider.GetBundle(absBundlePath)
		if err != nil {
			log.Fatal(err)
			return err
		}
		for i := 0; i < len(b.PosixSourceCommands()); i++ {
			fmt.Println(b.PosixSourceCommandsUsingLocation(prefixPath)[i])
		}

		return nil
	}
	app.Run(os.Args)
}