<commit_before>package cli

import (
	"github.com/SeerUK/tid/pkg/errhandling"
	"github.com/SeerUK/tid/pkg/tracking"
	"github.com/eidolon/console"
)

// ResumeCommand creates a command to resume timers.
func ResumeCommand(gateway tracking.Gateway) console.Command {
	execute := func(input *console.Input, output *console.Output) error {
		status, err := gateway.FindOrCreateStatus()
		if err != nil {
			return err
		}

		if status.IsActive() {
			output.Println("resume: Stop an existing timer before resuming a one")
			return nil
		}

		if status.Ref() == nil || status.Ref().Entry == "" {
			output.Println("resume: No timer to resume")
			return nil
		}

		sheet, err := gateway.FindOrCreateTimesheet(status.Ref().Timesheet)
		if err != nil {
			return err
		}

		entry, err := gateway.FindEntry(status.Ref().Entry)
		if err != nil {
			return err
		}

		// Update the time that this entry was last updated.
		entry.Update()

		status.Start(sheet, entry)

		errs := errhandling.NewErrorStack()
		errs.Add(gateway.PersistEntry(entry))
		errs.Add(gateway.PersistStatus(status))

		if err = errs.Errors(); err != nil {
			return err
		}

		// @todo: Consider adding onSuccess / postExecute to eidolon/console.
		output.Printf("Resumed tracking '%s' (%s)\n", entry.Note(), entry.ShortHash())

		return nil
	}

	return console.Command{
		Name:        "resume",
		Description: "Resume an existing timer.",
		Execute:     execute,
	}
}<commit_msg>You can now resume a specific entry.<commit_after>package cli

import (
	"github.com/SeerUK/tid/pkg/errhandling"
	"github.com/SeerUK/tid/pkg/tracking"
	"github.com/eidolon/console"
	"github.com/eidolon/console/parameters"
)

// ResumeCommand creates a command to resume timers.
func ResumeCommand(gateway tracking.Gateway) console.Command {
	var hash string

	configure := func(def *console.Definition) {
		def.AddArgument(
			parameters.NewStringValue(&hash),
			"[HASH]",
			"A short or long hash for an entry.",
		)
	}

	execute := func(input *console.Input, output *console.Output) error {
		status, err := gateway.FindOrCreateStatus()
		if err != nil {
			return err
		}

		if status.IsActive() {
			output.Println("resume: Stop an existing timer before resuming a one")
			return nil
		}

		if status.Ref() == nil || status.Ref().Entry == "" {
			output.Println("resume: No timer to resume")
			return nil
		}

		sheet, err := gateway.FindOrCreateTimesheet(status.Ref().Timesheet)
		if err != nil {
			return err
		}

		if hash == "" {
			hash = status.Ref().Entry
		}

		entry, err := gateway.FindEntry(hash)
		if err != nil {
			return err
		}

		// Update the time that this entry was last updated.
		entry.Update()

		status.Start(sheet, entry)

		errs := errhandling.NewErrorStack()
		errs.Add(gateway.PersistEntry(entry))
		errs.Add(gateway.PersistStatus(status))

		if err = errs.Errors(); err != nil {
			return err
		}

		// @todo: Consider adding onSuccess / postExecute to eidolon/console.
		output.Printf("Resumed tracking '%s' (%s)\n", entry.Note(), entry.ShortHash())

		return nil
	}

	return console.Command{
		Name:        "resume",
		Description: "Resume an existing timer.",
		Configure:   configure,
		Execute:     execute,
	}
}
{'fraction_non_alphanumeric': 0.13352095059412133, 'fraction_numerical': 0.0, 'mean_word_length': 3.4430555555555555, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2818714', 'n_tokens_mistral': 1182, 'n_tokens_neox': 1053, 'n_words': 270}