Пример #1
0
func dialog(msg string, stories []common.Story) (common.Story, error) {
	fmt.Println(msg)
	fmt.Println()

	dialog := storyprompt.NewDialog()
	dialog.PushOptions(storyprompt.NewIndexOption())
	dialog.PushOptions(storyprompt.NewReturnOrAbortOptions()...)
	dialog.PushOptions(storyprompt.NewFilterOption())
	return dialog.Run(stories)
}
Пример #2
0
func promptForStory(
	header string,
	stories []common.Story,
	reviewedStories []common.Story,
) (common.Story, error) {

	var (
		unassignedOpt *storyprompt.DialogOption
		reviewedOpt   *storyprompt.DialogOption
	)

	pushOptions := func(dialog *storyprompt.Dialog, opts ...*storyprompt.DialogOption) {
		dialog.PushOptions(storyprompt.NewIndexOption())
		dialog.PushOptions(opts...)
		dialog.PushOptions(storyprompt.NewReturnOrAbortOptions()...)
		dialog.PushOptions(storyprompt.NewFilterOption())
	}

	unassignedOpt = &storyprompt.DialogOption{
		Description: []string{
			"Insert 'u' to mark the commit(s) as unassigned",
		},
		IsActive: func(stories []common.Story, depth int) bool {
			return true
		},
		MatchesInput: func(input string, stories []common.Story) bool {
			return input == "u"
		},
		SelectStory: func(
			input string,
			stories []common.Story,
			currentDialog *storyprompt.Dialog,
		) (common.Story, error) {

			return nil, nil
		},
	}

	reviewedOpt = &storyprompt.DialogOption{
		Description: []string{
			"Insert 'r' to select a reviewed story",
		},
		IsActive: func(stories []common.Story, depth int) bool {
			return depth == 1
		},
		MatchesInput: func(input string, stories []common.Story) bool {
			return input == "r"
		},
		SelectStory: func(
			input string,
			stories []common.Story,
			currentDialog *storyprompt.Dialog,
		) (common.Story, error) {

			fmt.Println()
			fmt.Println("Showing the stories that are already reviewed ...")
			fmt.Println()

			subdialog := currentDialog.NewSubdialog()
			pushOptions(subdialog, unassignedOpt)
			return subdialog.Run(reviewedStories)
		},
	}

	fmt.Println(header)
	fmt.Println()

	dialog := storyprompt.NewDialog()
	pushOptions(dialog, unassignedOpt, reviewedOpt)
	return dialog.Run(stories)
}