<commit_before>// Copyright © 2016 National Data Service

package cmd

import (
	"encoding/json"
	"fmt"
	"github.com/spf13/cobra"
	"os"
	"text/tabwriter"
)

// listCmd represents the list command
var listCmd = &cobra.Command{
	Use:   "list",
	Short: "List available services or resources",
}

var listServicesCmd = &cobra.Command{
	Use:    "services",
	Short:  "List available services",
	PreRun: Connect,
	Run: func(cmd *cobra.Command, args []string) {

		services, err := client.ListServices()
		if err != nil {
			fmt.Printf("Error listing services: %s\n", err)
			return
		}

		w := new(tabwriter.Writer)
		w.Init(os.Stdout, 10, 4, 3, ' ', 0)
		fmt.Fprintln(w, "SERVICE\tDEPENDENCY\tREQUIRED")
		for _, service := range *services {
			if service.IsStack {
				fmt.Fprintf(w, "%s\n", service.Key)
				for _, dependency := range service.Dependencies {
					if dependency.Required {
						fmt.Fprintf(w, "\t%s\t(required)\n", dependency.DependencyKey)
					} else {
						fmt.Fprintf(w, "\t%s\t(optional)\n", dependency.DependencyKey)
					}
				}
			}
		}
		w.Flush()
	},
	PostRun: RefreshToken,
}

var listStacksCmd = &cobra.Command{
	Use:    "stacks",
	Short:  "List existing stacks",
	PreRun: Connect,
	Run: func(cmd *cobra.Command, args []string) {

		stacks, err := client.ListStacks(apiUser.username)
		if err != nil {
			fmt.Printf("List failed: %s\n", err)
			os.Exit(-1)
		}
		w := new(tabwriter.Writer)
		w.Init(os.Stdout, 10, 4, 3, ' ', 0)
		fmt.Fprintln(w, "STACK\tSERVICE\tSTATUS\tSID")
		for _, stack := range *stacks {

			fmt.Fprintf(w, "%s\t\t%s\t%s\n", stack.Name, stack.Status, stack.Id)
			for _, service := range stack.Services {
				//spec, _ := client.GetService(service.Service)
				fmt.Fprintf(w, "\t%s\t%s\t%s\n", service.Service, service.Status, service.Id)
			}
		}
		w.Flush()
		if Verbose {
			data, _ := json.MarshalIndent(stacks, "", "   ")
			fmt.Println(string(data))
		}
	},
	PostRun: RefreshToken,
}

var listVolumesCmd = &cobra.Command{
	Use:    "volumes",
	Short:  "List existing volumes",
	PreRun: Connect,
	Run: func(cmd *cobra.Command, args []string) {

		volumes, err := client.ListVolumes(apiUser.username)
		if err != nil {
			fmt.Printf("List failed: %s\n", err)
			os.Exit(-1)
		}

		w := new(tabwriter.Writer)
		w.Init(os.Stdout, 10, 4, 3, ' ', 0)
		fmt.Fprintln(w, "NAME\tATTACHED TO\tSIZE\tSTATUS")
		for _, volume := range *volumes {
			fmt.Fprintf(w, "%s\t%s\t%d\t%s\n", volume.Name, volume.Attached, volume.Size, volume.Status)
		}
		w.Flush()
	},
	PostRun: RefreshToken,
}

var listProjectsCmd = &cobra.Command{
	Use:    "projects",
	Short:  "List existing projects (admin users only)",
	PreRun: Connect,
	Run: func(cmd *cobra.Command, args []string) {

		password := credentials("<PASSWORD>: ")
		token, err := client.Login("admin", password)
		if err != nil {
			fmt.Printf("Unable to list projects: %s \n", err)
			return
		}

		projects, err := client.ListProjects(token)
		if err != nil {
			fmt.Printf("List failed: %s\n", err)
			os.Exit(-1)
		}

		w := new(tabwriter.Writer)
		w.Init(os.Stdout, 10, 4, 3, ' ', 0)
		fmt.Fprintln(w, "ID\tNAMESPACE")
		for _, project := range *projects {
			fmt.Fprintf(w, "%s\t%s\n", project.Id, project.Namespace)
		}
		w.Flush()<commit_msg>Changed output of list projects command<commit_after>// Copyright © 2016 National Data Service

package cmd

import (
	"encoding/json"
	"fmt"
	"github.com/spf13/cobra"
	"os"
	"text/tabwriter"
)

// listCmd represents the list command
var listCmd = &cobra.Command{
	Use:   "list",
	Short: "List available services or resources",
}

var listServicesCmd = &cobra.Command{
	Use:    "services",
	Short:  "List available services",
	PreRun: Connect,
	Run: func(cmd *cobra.Command, args []string) {

		services, err := client.ListServices()
		if err != nil {
			fmt.Printf("Error listing services: %s\n", err)
			return
		}

		w := new(tabwriter.Writer)
		w.Init(os.Stdout, 10, 4, 3, ' ', 0)
		fmt.Fprintln(w, "SERVICE\tDEPENDENCY\tREQUIRED")
		for _, service := range *services {
			if service.IsStack {
				fmt.Fprintf(w, "%s\n", service.Key)
				for _, dependency := range service.Dependencies {
					if dependency.Required {
						fmt.Fprintf(w, "\t%s\t(required)\n", dependency.DependencyKey)
					} else {
						fmt.Fprintf(w, "\t%s\t(optional)\n", dependency.DependencyKey)
					}
				}
			}
		}
		w.Flush()
	},
	PostRun: RefreshToken,
}

var listStacksCmd = &cobra.Command{
	Use:    "stacks",
	Short:  "List existing stacks",
	PreRun: Connect,
	Run: func(cmd *cobra.Command, args []string) {

		stacks, err := client.ListStacks(apiUser.username)
		if err != nil {
			fmt.Printf("List failed: %s\n", err)
			os.Exit(-1)
		}
		w := new(tabwriter.Writer)
		w.Init(os.Stdout, 10, 4, 3, ' ', 0)
		fmt.Fprintln(w, "STACK\tSERVICE\tSTATUS\tSID")
		for _, stack := range *stacks {

			fmt.Fprintf(w, "%s\t\t%s\t%s\n", stack.Name, stack.Status, stack.Id)
			for _, service := range stack.Services {
				//spec, _ := client.GetService(service.Service)
				fmt.Fprintf(w, "\t%s\t%s\t%s\n", service.Service, service.Status, service.Id)
			}
		}
		w.Flush()
		if Verbose {
			data, _ := json.MarshalIndent(stacks, "", "   ")
			fmt.Println(string(data))
		}
	},
	PostRun: RefreshToken,
}

var listVolumesCmd = &cobra.Command{
	Use:    "volumes",
	Short:  "List existing volumes",
	PreRun: Connect,
	Run: func(cmd *cobra.Command, args []string) {

		volumes, err := client.ListVolumes(apiUser.username)
		if err != nil {
			fmt.Printf("List failed: %s\n", err)
			os.Exit(-1)
		}

		w := new(tabwriter.Writer)
		w.Init(os.Stdout, 10, 4, 3, ' ', 0)
		fmt.Fprintln(w, "NAME\tATTACHED TO\tSIZE\tSTATUS")
		for _, volume := range *volumes {
			fmt.Fprintf(w, "%s\t%s\t%d\t%s\n", volume.Name, volume.Attached, volume.Size, volume.Status)
		}
		w.Flush()
	},
	PostRun: RefreshToken,
}

var listProjectsCmd = &cobra.Command{
	Use:    "projects",
	Short:  "List existing projects (admin users only)",
	PreRun: Connect,
	Run: func(cmd *cobra.Command, args []string) {

		password := credentials("<PASSWORD>: ")
		token, err := client.Login("admin", password)
		if err != nil {
			fmt.Printf("Unable to list projects: %s \n", err)
			return
		}

		projects, err := client.ListProjects(token)
		if err != nil {
			fmt.Printf("List failed: %s\n", err)
			os.Exit(-1)
		}

		w := new(tabwriter.Writer)
		w.Init(os.Stdout, 10, 4, 3, ' ', 0)
		fmt.Fprintln(w, "NAMESPACE\tQUOTA\tDESCRIPTION")
		for _, project := range *projects {
			fmt.Fprintf(w, "%s\t%d\t%s\n", project.Namespace, project.StorageQuota, project.Description)
		}
		w.Flush()
{'fraction_non_alphanumeric': 0.17203480384674097, 'fraction_numerical': 0.00885361013585712, 'mean_word_length': 3.403225806451613, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2439002', 'n_tokens_mistral': 2832, 'n_tokens_neox': 2540, 'n_words': 549}