<commit_before>package main

import (
	tickspot "github.com/nicored/gotickyourself"

	"regexp"

	"strconv"

	"strings"
	"time"

	"fmt"

	"log"
	"os"

	"github.com/jinzhu/now"
	"github.com/spf13/cobra"
)

func getLogCmd() *cobra.Command {
	logCmd := &cobra.Command{
		Use:    "log",
		Short:  "log new entries",
		Long:   ``,
		PreRun: initConfigFiles,
		Run:    runLogCmd,
	}

	logCmd.Flags().StringP("notes", "n", "", "Add notes to the log")
	logCmd.Flags().StringP("date", "d", "today", "Is the date for which the hours must be logged (default is today). (eg. '2017-07-02', 'yesterday', 'today'")

	return logCmd
}

//$ gty log # Log all day  (default task, default time)

func runLogCmd(cmd *cobra.Command, args []string) {
	const logSpecificHours = 1
	const logPeriod = 2

	logType := logPeriod
	task := projectsConfig.DefaultTask
	logHours := -1.0

	nArgs := 0
	period := ""

	expectedHours := getHoursPerDay()
	todayHours := make(chan float64)
	todayEntriesErr := make(chan error)
	dateArg := cmd.Flag("date").Value.String()

	if len(args) >= 1 && isSimplePeriod(args[0]) {
		period = args[0]
		nArgs += 1
	} else if len(args) >= 2 && isPeriodWithCount(strings.Join(args[0:1], " ")) {
		period = strings.Join(args[0:1], " ")
		nArgs += 2
	} else if len(args) > 0 {
		hours, isHours := getHours(args[0])
		if isHours && hours > 0 {
			logHours = hours
			nArgs += 1
			logType = logSpecificHours
		} else if hours == 0 {
			log.Println("Error: Hours must be between 0 and 24")
			os.Exit(1)
		}
	}

	if len(args) > nArgs {
		t, ok := aliases[args[nArgs]]
		errfOnMismatch(ok, true, "aliases %s does not exist\n", args[nArgs])
		task = t
	}

	if task == nil {
		log.Println("You must specify a task, or have a default task available for use")
		os.Exit(1)
	}

	if logType == logSpecificHours || period == "" {
		var err error

		date, err := parseDate(dateArg)
		if logHours < 0 {
			entries, err := tick.GetEntries(tickspot.DateRange{date, date})
			errfOnMismatch(err, nil, "Could not load entries")
			dayHours := getTotalEntriesHours(entries)

			if dayHours < expectedHours {<commit_msg>fix(log): Fixed logging without specifying the hours<commit_after>package main

import (
	tickspot "github.com/nicored/gotickyourself"

	"regexp"

	"strconv"

	"strings"
	"time"

	"fmt"

	"log"
	"os"

	"github.com/jinzhu/now"
	"github.com/spf13/cobra"
)

func getLogCmd() *cobra.Command {
	logCmd := &cobra.Command{
		Use:    "log",
		Short:  "log new entries",
		Long:   ``,
		PreRun: initConfigFiles,
		Run:    runLogCmd,
	}

	logCmd.Flags().StringP("notes", "n", "", "Add notes to the log")
	logCmd.Flags().StringP("date", "d", "today", "Is the date for which the hours must be logged (default is today). (eg. '2017-07-02', 'yesterday', 'today'")

	return logCmd
}

//$ gty log # Log all day  (default task, default time)

func runLogCmd(cmd *cobra.Command, args []string) {
	const logSpecificHours = 1
	const logPeriod = 2

	logType := logPeriod
	task := projectsConfig.DefaultTask
	logHours := -1.0

	nArgs := 0
	period := ""

	expectedHours := getHoursPerDay()
	todayHours := make(chan float64)
	todayEntriesErr := make(chan error)
	dateArg := cmd.Flag("date").Value.String()

	if len(args) >= 1 && isSimplePeriod(args[0]) {
		period = args[0]
		nArgs += 1
	} else if len(args) >= 2 && isPeriodWithCount(strings.Join(args[0:1], " ")) {
		period = strings.Join(args[0:1], " ")
		nArgs += 2
	} else if len(args) > 0 {
		hours, isHours := getHours(args[0])
		if isHours && hours > 0 {
			logHours = hours
			nArgs += 1
			logType = logSpecificHours
		} else if isHours && hours == 0 {
			log.Println("Error: Hours must be between 0 and 24")
			os.Exit(1)
		}
	}

	if len(args) > nArgs {
		t, ok := aliases[args[nArgs]]
		errfOnMismatch(ok, true, "aliases %s does not exist\n", args[nArgs])
		task = t
	}

	if task == nil {
		log.Println("You must specify a task, or have a default task available for use")
		os.Exit(1)
	}

	if logType == logSpecificHours || period == "" {
		var err error

		date, err := parseDate(dateArg)
		if logHours < 0 {
			entries, err := tick.GetEntries(tickspot.DateRange{date, date})
			errfOnMismatch(err, nil, "Could not load entries")
			dayHours := getTotalEntriesHours(entries)

			if dayHours < expectedHours {
{'fraction_non_alphanumeric': 0.15346534653465346, 'fraction_numerical': 0.017916077322017915, 'mean_word_length': 3.667766776677668, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '6017744', 'n_tokens_mistral': 1770, 'n_tokens_neox': 1597, 'n_words': 419}