Starting work on glob support. Refs ~petersanchez/tago#7
2 files changed, 60 insertions(+), 16 deletions(-)

M cmd/tag.go
M lib/helpers.go
M cmd/tag.go +40 -16
@@ 49,13 49,6 @@ func TagFile(cmd *cobra.Command, args []
 
 	if ltags == "" {
 		// One file
-		file := lib.NewFile(qm, args[0])
-		file.IsIndex = index
-		file.IndexDesc = desc
-		if err := file.Load(qm, true); err != nil {
-			return err
-		}
-
 		tags := make([]lib.Tag, 0, len(args[1:]))
 		for _, arg := range args[1:] {
 			if tag, err := lib.ValidateTagName(arg); err != nil {

          
@@ 69,10 62,27 @@ func TagFile(cmd *cobra.Command, args []
 			return fmt.Errorf("No valid tags were given")
 		}
 
-		if err := file.Tag(qm, tags...); err != nil {
+		files, err := lib.NewFiles(qm, args[0])
+		if err != nil {
 			return err
 		}
-		fmt.Println(lib.RelativePath(file.FullPath()))
+
+		for _, file := range files {
+			file.IsIndex = index
+			file.IndexDesc = desc
+			if err := file.Load(qm, true); err != nil {
+				if len(files) == 1 {
+					return err
+				}
+				fmt.Println(err)
+				continue
+			}
+
+			if err := file.Tag(qm, tags...); err != nil {
+				return err
+			}
+			fmt.Println(lib.RelativePath(file.FullPath()))
+		}
 	} else {
 		// Potentially multiple files
 		ptags, err := shlex.Split(ltags)

          
@@ 90,18 100,32 @@ func TagFile(cmd *cobra.Command, args []
 			}
 		}
 
+		if len(tags) == 0 {
+			return fmt.Errorf("No valid tags were given")
+		}
+
 		// Tag each file
 		for _, arg := range args {
-			file := lib.NewFile(qm, arg)
-			file.IsIndex = index
-			file.IndexDesc = desc
-			if err := file.Load(qm, true); err != nil {
+			files, err := lib.NewFiles(qm, arg)
+			if err != nil {
 				return err
 			}
-			if err := file.Tag(qm, tags...); err != nil {
-				return err
+
+			for _, file := range files {
+				file.IsIndex = index
+				file.IndexDesc = desc
+				if err := file.Load(qm, true); err != nil {
+					if len(files) == 1 {
+						return err
+					}
+					fmt.Println(err)
+					continue
+				}
+				if err := file.Tag(qm, tags...); err != nil {
+					return err
+				}
+				fmt.Println(lib.RelativePath(file.FullPath()))
 			}
-			fmt.Println(lib.RelativePath(file.FullPath()))
 		}
 	}
 	return nil

          
M lib/helpers.go +20 -0
@@ 68,6 68,26 @@ func NewFile(qm *QueryManager, fname str
 	return file
 }
 
+// NewFiles returns a slice of *File objects
+func NewFiles(qm *QueryManager, fname string) ([]*File, error) {
+	files := make([]*File, 0)
+	matches, err := filepath.Glob(fname)
+	if err != nil {
+		return nil, err
+	}
+
+	if len(matches) > 0 {
+		for _, match := range matches {
+			file := NewFile(qm, match)
+			files = append(files, file)
+		}
+	} else {
+		file := NewFile(qm, fname)
+		files = append(files, file)
+	}
+	return files, nil
+}
+
 // ValidateTagName ensures given tag(s) are valid
 func ValidateTagName(tag string) (string, error) {
 	tag = strings.ToLower(tag) // Always lowercase