// Copyright (C) 2017 Damon Revoe. All rights reserved.
// Use of this source code is governed by the MIT
// license, which can be found in the LICENSE file.

package main

func listPackages(workspacedir, pkgpath string) error {
	packageIndex, err := buildPackageIndex(pkgpath)

	if err != nil {
		return err
	}

	packageIndex.printListOfPackages()

	return nil
}

// Copyright (C) 2017 Damon Revoe. All rights reserved.
// Use of this source code is governed by the MIT
// license, which can be found in the LICENSE file.

package main

import (
	"log"

	"github.com/spf13/cobra"
)

func listPackages() error {
	packageIndex, err := buildPackageIndex(flags.pkgPath)

	if err != nil {
		return err
	}

	packageIndex.printListOfPackages()

	return nil
}

// listCmd represents the init command
var listCmd = &cobra.Command{
	Use:   "list",
	Short: "Print the list of packages found in $" + pkgPathEnvVar,
	Args:  cobra.MaximumNArgs(0),
	Run: func(cmd *cobra.Command, args []string) {
		if err := listPackages(); err != nil {
			log.Fatal(err)
		}
	},
}

func init() {
	RootCmd.AddCommand(listCmd)

	listCmd.Flags().SortFlags = false
	addWorkspaceDirFlag(listCmd)
	addPkgPathFlag(listCmd)
}

Add the 'list' command using cobra
Add the 'list' command using cobra
