Esempio n. 1
0
// Handles arguments and dispatches subcommand.
func blobCmd(c *commander.Command, args []string) (blobPaths, error) {

	blobs := blobPaths{}

	// Use all blobs in the manifest if --all is passed in.
	all := c.Flag.Lookup("all").Value.Get().(bool)
	if all {
		mf := NewDefaultManifest()
		blobs = validBlobHashes(mf.Files)
		if len(blobs) < 1 {
			return nil, fmt.Errorf("%v: no blobs tracked in manifest.", c.FullName())
		}
	} else {
		switch len(args) {
		case 2:
			blobs[args[1]] = args[0]
		case 1:
			blobs[""] = args[0]
		case 0:
			return nil,
				fmt.Errorf("%v: requires <hash> argument (or --all)", c.FullName())
		}
	}

	return blobs, nil
}
Esempio n. 2
0
func configCmd(c *commander.Command, args []string) error {
	if c.Flag.Lookup("show").Value.Get().(bool) {
		return printConfig(&Config)
	}

	if c.Flag.Lookup("edit").Value.Get().(bool) {
		return configEditor()
	}

	if len(args) == 0 {
		return fmt.Errorf("%s: requires <key> argument.", c.Name())
	}

	if len(args) == 1 {
		value := ConfigGet(args[0])
		if value == nil {
			return fmt.Errorf("") // empty string prints out nothing.
		}

		m, err := Marshal(value)
		if err != nil {
			return err
		}
		io.Copy(os.Stdout, m)
		return nil
	}

	return ConfigSet(args[0], args[1])
}
Esempio n. 3
0
func blobCheckCmd(c *commander.Command, args []string) error {
	blobs, err := blobCmd(c, args)
	if err != nil {
		return err
	}
	if len(args) == 1 {
		return fmt.Errorf("%v: requires <path> argument", c.FullName())
	}
	return checkBlobs(blobs)
}
Esempio n. 4
0
func commandsCmd(c *commander.Command, args []string) error {
	var listCmds func(c *commander.Command)
	listCmds = func(c *commander.Command) {
		pOut("%s\n", c.FullSpacedName())
		for _, sc := range c.Subcommands {
			listCmds(sc)
		}
	}

	listCmds(c.Parent)
	return nil
}
Esempio n. 5
0
func blobHashCmd(c *commander.Command, args []string) error {
	if len(args) < 1 {
		return fmt.Errorf("%v: requires <path> argument", c.FullName())
	}

	hash, err := hashFile(args[0])
	if err != nil {
		return err
	}
	pOut("%s\n", hash)
	return nil
}
Esempio n. 6
0
func blobShowCmd(c *commander.Command, args []string) error {
	if len(args) < 1 {
		return fmt.Errorf("%v: requires <hash> argument", c.FullName())
	}

	hash := args[0]
	if !IsHash(hash) {
		return fmt.Errorf("%v: invalid hash '%s'", c.FullName(), hash)
	}

	dataIndex, err := NewMainDataIndex()
	if err != nil {
		return err
	}

	return dataIndex.copyBlob(hash, os.Stdout)
}
Esempio n. 7
0
func getCmd(c *commander.Command, args []string) error {
	var datasets []string

	if len(args) > 0 {
		// if args, get those datasets.
		datasets = args
	} else {
		// if no args, use Datafile dependencies
		df, _ := NewDefaultDatafile()
		for _, dep := range df.Dependencies {
			if NewHandle(dep).Valid() {
				datasets = append(datasets, dep)
			}
		}
	}

	if len(datasets) == 0 {
		return fmt.Errorf("%v: no datasets specified.\nEither enter a <dataset> "+
			"argument, or add dependencies in a Datafile.", c.FullName())
	}

	installed_datasets := []string{}
	for _, ds := range datasets {
		ds, err := GetDataset(ds)
		if err != nil {
			return err
		}
		installed_datasets = append(installed_datasets, ds)
	}

	if len(datasets) == 0 {
		return nil
	}

	// If many, Installation Summary
	pErr("---------\n")
	for _, ds := range installed_datasets {
		err := installedDatasetMessage(ds)
		if err != nil {
			pErr("%v\n", err)
		}
	}
	return nil
}
Esempio n. 8
0
func manifestCmdPaths(c *commander.Command, args []string) ([]string, error) {
	mf := NewDefaultManifest()
	paths := args

	// Use all files available if --all is passed in.
	all := c.Flag.Lookup("all").Value.Get().(bool)
	if all {
		paths = []string{}
		for path, _ := range mf.Files {
			paths = append(paths, path)
		}
	}

	if len(paths) < 1 {
		return nil, fmt.Errorf("%v: no files specified.", c.FullName())
	}

	return paths, nil
}
Esempio n. 9
0
func commandsHelpCmd(c *commander.Command, args []string) error {
	pOut(referenceHeaderMsg)
	pOut("Generated on %s.\n\n", time.Now().UTC().Format("2006-01-02"))

	var printCmds func(*commander.Command, int)
	printCmds = func(c *commander.Command, level int) {
		pOut("%s ", strings.Repeat("#", level))
		pOut("%s\n\n", c.FullSpacedName())
		pOut("```\n")
		pOut("%s\n", c.Long)
		pOut("```\n\n")

		for _, sc := range c.Subcommands {
			printCmds(sc, level+1)
		}
	}

	printCmds(c.Parent.Parent, 1)
	return nil
}
Esempio n. 10
0
func manifestAddCmd(c *commander.Command, args []string) error {
	mf := NewDefaultManifest()
	paths := args

	// Use all files available if --all is passed in.
	all := c.Flag.Lookup("all").Value.Get().(bool)
	if all {
		paths = listAllFiles(".")
	}

	if len(paths) < 1 {
		return fmt.Errorf("%v: no files specified.", c.FullName())
	}

	// add files to manifest file
	for _, f := range paths {
		err := mf.Add(f)
		if err != nil {
			return err
		}
	}

	return nil
}
Esempio n. 11
0
func ex_run_cmd_subcmd2_cmd2(cmd *commander.Command, args []string) error {
	name := "my-cmd-subcmd2-" + cmd.Name()
	quiet := cmd.Flag.Lookup("q").Value.Get().(bool)
	fmt.Printf("%s: hello from subcmd2-cmd2 (quiet=%v)\n", name, quiet)
	return nil
}