commands

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2017 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Init = cli.Command{
	Name:  "init",
	Usage: "Prepare the current project directory for go-to-work",
	Action: func(c *cli.Context) (err error) {

		cfg, _ := config.DefaultConfig()

		fmt.Print("\n")

		harvest := service.NewHarvestService()
		accountID := cfg.Harvest.AccountID

		var token string

		prompts.HarvestBanner()
		if accountID == "" || !service.HasCredentials(harvest) {
			accountID, token = prompts.Harvest()
			cfg.Harvest.AccountID = accountID
			cfg.SaveDefaultConfig()
			service.SaveCredentials(harvest, token)
		} else {
			accountID = cfg.Harvest.AccountID
			token, err = service.LoadCredentials(harvest)
			if err != nil {
				println("Could not load Harvest credentials")
			}
		}

		err = harvest.SignIn(accountID, token)
		if err != nil {
			fmt.Println(err)
			println("Error: Harvest Authentication failed.")
		}

		projAssignment := prompts.HarvestChooseProject(harvest.GetProjects())
		cfg.Harvest.ProjectID = strconv.FormatInt(projAssignment.Project.ID, 10)
		cfg.SaveDefaultConfig()

		taskAssignments := harvest.GetTasks(projAssignment)
		taskAssignment := prompts.HarvestChooseTask(taskAssignments)

		cfg.Harvest.TaskID = strconv.FormatInt(taskAssignment.Task.ID, 10)
		cfg.SaveDefaultConfig()

		fmt.Print("\n\n")

		pt := service.NewPivotalTrackerService()

		prompts.PivotalTrackerBanner()
		if !service.HasCredentials(pt) {
			token = prompts.PivotalTracker()

			cfg.SaveDefaultConfig()
			service.SaveCredentials(pt, token)
		} else {
			token, err = service.LoadCredentials(pt)
			if err != nil {
				println("Could not load PivotalTracker credentials")
			}
		}

		pt.SignIn(token)
		projects, _ := pt.GetProjects()
		ptproj := prompts.PivotalTrackerChooseProject(projects)
		cfg.PivotalTracker.ProjectID = strconv.FormatInt(int64(ptproj.Id), 10)
		cfg.SaveDefaultConfig()

		return nil
	},
}

Init prepares the project directory for use

View Source
var Start = cli.Command{
	Name:  "start",
	Usage: "Start a timer",
	Action: func(c *cli.Context) (err error) {
		// Create a configuration file
		var token string
		var ptStoryID int
		cfg, _ := config.DefaultConfig()

		harvest := service.NewHarvestService()
		token, _ = service.LoadCredentials(harvest)
		err = harvest.SignIn(cfg.Harvest.AccountID, token)

		pt := service.NewPivotalTrackerService()
		token, _ = service.LoadCredentials(pt)
		pt.SignIn(token)

		firstArg := c.Args().Get(0)
		if firstArg == "" {
			ptStoryID = cfg.PivotalTracker.LastStoryID
		} else {
			ptStoryID = GetPTStoryID(firstArg)
		}

		if ptStoryID == 0 {
			fmt.Println("")
			fmt.Println("")
			color.Red("Could not find a previously started story.\nPlease pass a Pivotal Tracker Stroy URL as an argument")
			return
		}

		projID, _ := strconv.Atoi(cfg.PivotalTracker.ProjectID)
		story := pt.GetStory(projID, ptStoryID)

		cfg.Harvest.LatTimeEntryID, err = harvest.StartTimer(cfg.Harvest.ProjectID, cfg.Harvest.TaskID, story.Name+"\n\n"+story.URL)
		if err != nil {
			fmt.Println(err)
			return
		}

		cfg.PivotalTracker.LastStoryID = ptStoryID
		cfg.SaveDefaultConfig()

		return nil

	},
}

Init prepares the project directory for use

View Source
var Stop = cli.Command{
	Name:  "stop",
	Usage: "Stop your last running timer",
	Action: func(c *cli.Context) (err error) {
		cfg, _ := config.DefaultConfig()
		harvest := service.NewHarvestService()
		token, _ := service.LoadCredentials(harvest)
		err = harvest.SignIn(cfg.Harvest.AccountID, token)

		if err != nil {
			return
		}

		entryID := cfg.Harvest.LatTimeEntryID

		if entryID == 0 {
			fmt.Println("\n\nNo existing time entry found. No timer has been stopped.")
			return
		}

		harvest.Stoptimer(entryID)
		return
	},
}

Init prepares the project directory for use

Functions

func GetPTStoryID

func GetPTStoryID(URL string) int

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL