From 1cd848264dc422e5d70b9672a4f8ad5efc962427 Mon Sep 17 00:00:00 2001
From: Noah Reinalter <38698485+noahreinalter@users.noreply.github.com>
Date: Sat, 26 Aug 2023 16:54:00 +0200
Subject: [PATCH] Optionally show filenames in list output (#248)

---
 cmd/list.go | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/cmd/list.go b/cmd/list.go
index ee70572..cce5909 100644
--- a/cmd/list.go
+++ b/cmd/list.go
@@ -3,9 +3,11 @@ package cmd
 import (
 	"fmt"
 	"os"
+	"sort"
 
 	"github.com/packwiz/packwiz/core"
 	"github.com/spf13/cobra"
+	"github.com/spf13/viper"
 )
 
 // listCmd represents the list command
@@ -36,13 +38,26 @@ var listCmd = &cobra.Command{
 			os.Exit(1)
 		}
 
+		sort.Slice(mods, func(i, j int) bool {
+			return mods[i].Name < mods[j].Name
+		})
+
 		// Print mods
-		for _, mod := range mods {
-			fmt.Println(mod.Name)
+		if viper.GetBool("list.version") {
+			for _, mod := range mods {
+				fmt.Printf("%s\t[%s]\n", mod.Name, mod.FileName)
+			}
+		} else {
+			for _, mod := range mods {
+				fmt.Println(mod.Name)
+			}
 		}
 	},
 }
 
 func init() {
 	rootCmd.AddCommand(listCmd)
+
+	listCmd.Flags().BoolP("version", "v", false, "Print name and version")
+	_ = viper.BindPFlag("list.version", listCmd.Flags().Lookup("version"))
 }