Exemple #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
}
Exemple #2
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)
}
Exemple #3
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
}
Exemple #4
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)
}
Exemple #5
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
}
Exemple #6
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
}
Exemple #7
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
}