Ejemplo n.º 1
0
func DoCollection(c *cli.Context) {
	useOptions(c)

	args := c.Args()
	if len(args) == 0 {
		term.Println("Too few arguments")
		return
	}

	name := args[0]
	collection, err := account.GetCollectionByName(name)
	if err == nil {
		term.Printf("Collection %s exists:\n", collection.CollectionName)
		if len(args) > 1 {
			term.Println("(Column arguments ignored)")
		}
		term.Section()
		showCollectionInfo(collection)
		return
	}

	schema, err := schemaWithColumns(args[1:])
	if err != nil {
		term.Println(err.Error())
		return
	}

	createCollection(name, schema)
}
Ejemplo n.º 2
0
func DoFind(c *cli.Context) {
	useOptions(c)

	args := c.Args()
	if len(args) == 0 {
		term.Println("Too few arguments")
		return
	}

	collection, err := account.GetCollectionByName(args[0])
	if err != nil {
		term.Println(err.Error())
		return
	}

	filter := ""
	if len(args) > 1 {
		filter = args[1]
	}

	objects, err := account.GetObjects(collection.CollectionName, filter)
	if err != nil {
		term.Println(err.Error())
		return
	}

	columns := collection.SortedColumnNames()
	rows := objectsAsStringTable(columns, objects)
	term.Layout(false)
	term.PrintTable(columns, rows)
}