Ejemplo n.º 1
0
func Identifier(args ArgumentList) {
	if len(args) < 1 {
		fmt.Printf("Usage: %s identifier BugID [value]\n", os.Args[0])
		return
	}

	b, err := bugs.LoadBugByHeuristic(args[0])
	if err != nil {
		fmt.Printf("Invalid BugID: %s\n", err.Error())
		return
	}
	if len(args) > 1 {
		var newValue string
		if args.HasArgument("--generate") {
			newValue = generateID(b.Title(""))
			fmt.Printf("Generated id %s for bug\n", newValue)
		} else {
			newValue = strings.Join(args[1:], " ")
		}
		err := b.SetIdentifier(newValue)
		if err != nil {
			fmt.Printf("Error setting identifier: %s", err.Error())
		}
	} else {
		val := b.Identifier()
		if val == "" {
			fmt.Printf("Identifier not defined\n")
		} else {
			fmt.Printf("%s\n", val)
		}
	}
}
Ejemplo n.º 2
0
func fieldHandler(command string, args ArgumentList,
	setCallback func(bugs.Bug, string) error, retrieveCallback func(bugs.Bug) string) {
	if len(args) < 1 {
		fmt.Printf("Usage: %s %s BugID [set %s]\n", os.Args[0], command, command)
		return
	}

	b, err := bugs.LoadBugByHeuristic(args[0])
	if err != nil {
		fmt.Printf("Invalid BugID: %s\n", err.Error())
		return
	}
	if len(args) > 1 {
		newValue := strings.Join(args[1:], " ")
		err := setCallback(*b, newValue)
		if err != nil {
			fmt.Printf("Error setting %s: %s", command, err.Error())
		}
	} else {
		val := retrieveCallback(*b)
		if val == "" {
			fmt.Printf("%s not defined\n", command)
		} else {
			fmt.Printf("%s\n", val)
		}
	}
}
Ejemplo n.º 3
0
Archivo: Tag.go Proyecto: Komosa/bug
func Tag(Args ArgumentList) {
	if len(Args) < 2 {
		fmt.Printf("Usage: %s tag [--rm] BugID tagname [more tagnames]\n", os.Args[0])
		fmt.Printf("\nBoth issue number and tagname to set are required.\n")
		fmt.Printf("\nCurrently used tags in entire tree: %s\n", strings.Join(getAllTags(), ", "))
		return
	}
	var removeTags bool = false
	if Args[0] == "--rm" {
		removeTags = true
		Args = Args[1:]
	}

	b, err := bugs.LoadBugByHeuristic(Args[0])

	if err != nil {
		fmt.Printf("Could not load bug: %s\n", err.Error())
		return
	}
	for _, tag := range Args[1:] {
		if removeTags {
			b.RemoveTag(bugs.Tag(tag))
		} else {
			b.TagBug(bugs.Tag(tag))
		}
	}

}
Ejemplo n.º 4
0
Archivo: List.go Proyecto: Komosa/bug
func List(args ArgumentList, stdout *os.File) {
	issues, _ := ioutil.ReadDir(string(bugs.GetIssuesDir()))

	var wantTags bool = false
	if args.HasArgument("--tags") {
		wantTags = true
	}

	// No parameters, print a list of all bugs
	if len(args) == 0 || (wantTags && len(args) == 1) {
		//os.Stdout = stdout
		for idx, issue := range issues {
			if issue.IsDir() != true {
				continue
			}
			var dir bugs.Directory = bugs.GetIssuesDir() + bugs.Directory(issue.Name())
			b := bugs.Bug{dir}
			name := getBugName(b, idx)
			if wantTags == false {
				fmt.Printf("%s: %s\n", name, b.Title(""))
			} else {
				fmt.Printf("%s: %s\n", name, b.Title("tags"))
			}
		}
		return
	}

	// getAllTags() is defined in Tag.go
	// Get a list of tags, so that when we encounter
	// an error we can check if it's because the user
	// provided a tagname instead of a BugID. If they
	// did, then list bugs matching that tag instead
	// of full descriptions
	tags := getAllTags()
	// There were parameters, so show the full description of each
	// of those issues
	for i, length := 0, len(args); i < length; i += 1 {
		b, err := bugs.LoadBugByHeuristic(args[i])
		if err != nil {
			for _, tagname := range tags {
				if tagname == args[i] {
					listTags(issues, args)
					return
				}
			}
			fmt.Printf("%s\n", err.Error())
			continue
		}

		b.ViewBug()
		if i < length-1 {
			fmt.Printf("\n--\n\n")
		}
	}
	fmt.Printf("\n")
}
Ejemplo n.º 5
0
Archivo: Edit.go Proyecto: Komosa/bug
func Edit(args ArgumentList) {

	var file, bugID string
	switch len(args) {
	case 1:
		// If there's only 1 argument, it's an issue
		// identifier and it's editing the description.
		// So set the variables and fallthrough to the
		// 2 argument (editing a specific fieldname)
		// case
		bugID = args[0]
		file = "Description"
		fallthrough
	case 2:
		// If there's exactly 2 arguments, idx and
		// file haven't been set by the first case
		// statement, so set them, but everything else
		// is the same
		if len(args) == 2 {
			bugID = args[1]
			file = args[0]
		}

		b, err := bugs.LoadBugByHeuristic(bugID)
		if err != nil {
			fmt.Printf("Invalid BugID %s\n", bugID)
			return
		}

		dir := b.GetDirectory()

		switch title := strings.Title(file); title {
		case "Milestone", "Status", "Priority", "Identifier":
			file = title
		}
		fmt.Printf("Launching in %s/%s", dir, file)
		cmd := exec.Command(getEditor(), string(dir)+"/"+file)

		cmd.Stdin = os.Stdin
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr

		err = cmd.Run()
		if err != nil {
			log.Fatal(err)
		}
	default:
		fmt.Printf("Usage: %s edit [fieldname] BugID\n", os.Args[0])
		fmt.Printf("\nNo BugID specified\n")
	}
}
Ejemplo n.º 6
0
Archivo: Close.go Proyecto: Komosa/bug
func Close(args ArgumentList) {
	// No parameters, print a list of all bugs
	if len(args) == 0 {
		fmt.Fprintf(os.Stderr, "Usage: %s close BugID\n\nMust provide an BugID to close as parameter\n", os.Args[0])
		return
	}

	// There were parameters, so show the full description of each
	// of those issues
	for _, bugID := range args {
		if bug, err := bugs.LoadBugByHeuristic(bugID); err == nil {
			dir := bug.GetDirectory()
			fmt.Printf("Removing %s\n", dir)
			os.RemoveAll(string(dir))
		} else {
			fmt.Printf("Could not close bug %s: %s\n", bugID, err)
		}
	}
}
Ejemplo n.º 7
0
func Relabel(Args ArgumentList) {
	if len(Args) < 2 {
		fmt.Printf("Usage: %s relabel BugID New Title\n", os.Args[0])
		return
	}

	b, err := bugs.LoadBugByHeuristic(Args[0])

	if err != nil {
		fmt.Printf("Could not load bug: %s\n", err.Error())
		return
	}

	currentDir := b.GetDirectory()
	newDir := bugs.GetIssuesDir() + bugs.TitleToDir(strings.Join(Args[1:], " "))
	fmt.Printf("Moving %s to %s\n", currentDir, newDir)
	err = os.Rename(string(currentDir), string(newDir))
	if err != nil {
		fmt.Printf("Error moving directory\n")
	}
}