<commit_before>// Copyright © 2016 NAME HERE <EMAIL ADDRESS>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
	"fmt"
	"os"
	"strconv"

	fqdn "github.com/ShowMax/go-fqdn"
	humanize "github.com/dustin/go-humanize"
	"github.com/olekukonko/tablewriter"
	"github.com/spf13/cobra"
	"github.com/spf13/viper"
	"github.com/veino/bitfan/lib"
	"github.com/veino/veino/runtime"
)

func init() {
	RootCmd.AddCommand(listCmd)
	listCmd.Flags().StringP("host", "H", "127.0.0.1:5123", "Service Host to connect to")
}

// listCmd represents the list command
var listCmd = &cobra.Command{
	Use:     "list",
	Short:   "List running pipelines",
	Aliases: []string{"ls"},
	Long:    ``,
	PreRun: func(cmd *cobra.Command, args []string) {
		viper.BindPFlag("host", cmd.Flags().Lookup("host"))
	},
	Run: func(cmd *cobra.Command, args []string) {
		// TODO: Work your own magic here
		s := lib.ApiClient(viper.GetString("host"))

		// Send a request & read result
		var pipelines = map[int]*runtime.Pipeline{}
		if err := s.Request("findPipelines", "", &pipelines); err != nil {
			fmt.Printf("list error: %v\n", err.Error())
		} else {

			table := tablewriter.NewWriter(os.Stdout)
			table.SetHeader([]string{
				"ID",
				"name",
				"Started",
				"configuration",
			})

			for _, pipeline := range pipelines {
				host := ""
				if pipeline.ConfigHostLocation != fqdn.Get() {
					host = pipeline.ConfigHostLocation + "@"
				}

				table.Append([]string{
					strconv.Itoa(pipeline.ID),
					pipeline.Label,
					humanize.Time(pipeline.StartedAt),
					fmt.Sprintf("%s%s",
						host,
						pipeline.ConfigLocation),
				})
			}
			// table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
			table.SetCenterSeparator("+")
			table.Render()

		}
	},
}<commit_msg>remove StartedAt from pipeline list<commit_after>// Copyright © 2016 NAME HERE <EMAIL ADDRESS>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
	"fmt"
	"os"
	"strconv"

	fqdn "github.com/ShowMax/go-fqdn"
	"github.com/olekukonko/tablewriter"
	"github.com/spf13/cobra"
	"github.com/spf13/viper"
	"github.com/veino/bitfan/lib"
	"github.com/veino/veino/runtime"
)

func init() {
	RootCmd.AddCommand(listCmd)
	listCmd.Flags().StringP("host", "H", "127.0.0.1:5123", "Service Host to connect to")
}

// listCmd represents the list command
var listCmd = &cobra.Command{
	Use:     "list",
	Short:   "List running pipelines",
	Aliases: []string{"ls"},
	Long:    ``,
	PreRun: func(cmd *cobra.Command, args []string) {
		viper.BindPFlag("host", cmd.Flags().Lookup("host"))
	},
	Run: func(cmd *cobra.Command, args []string) {
		// TODO: Work your own magic here
		s := lib.ApiClient(viper.GetString("host"))

		// Send a request & read result
		var pipelines = map[int]*runtime.Pipeline{}
		if err := s.Request("findPipelines", "", &pipelines); err != nil {
			fmt.Printf("list error: %v\n", err.Error())
		} else {

			table := tablewriter.NewWriter(os.Stdout)
			table.SetHeader([]string{
				"ID",
				"name",
				"configuration",
			})

			for _, pipeline := range pipelines {
				host := ""
				if pipeline.ConfigHostLocation != fqdn.Get() {
					host = pipeline.ConfigHostLocation + "@"
				}

				table.Append([]string{
					strconv.Itoa(pipeline.ID),
					pipeline.Label,
					fmt.Sprintf("%s%s",
						host,
						pipeline.ConfigLocation),
				})
			}
			// table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
			table.SetCenterSeparator("+")
			table.Render()

		}
	},
}
{'fraction_non_alphanumeric': 0.15086870464042226, 'fraction_numerical': 0.009676709918627667, 'mean_word_length': 3.4370731707317073, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, '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': '4754734', 'n_tokens_mistral': 1711, 'n_tokens_neox': 1516, 'n_words': 404}