aboutsummaryrefslogtreecommitdiffstats
AgeCommit message (Collapse)Author
2017-06-04Add module.go for parsing Module XMLTeddy Wing
A new function that parses the XML returned by the `RequestModules()` function. It provides a `Module` type that allows us to interact with modules more easily in code. The `ParseXML()` function will take an XML string and return a slice of `Module`s. Added a test just to facilitate development. Wasn't able to find an easy way to compare slices in Go, so just printed the values and checked the result visually. Not a useful test for future use, but it served its purpose. Eventually it would be nice to find a way to compare structs and have a real pass/fail condition.
2017-06-03TestLogin(): Fix `Login()` assignment mismatchTeddy Wing
`Login()` now returns 3 values. Update the test.
2017-06-03Add an option to list "Modules" (sprints & their IDs)Teddy Wing
Sprints will change with time while the other IDs of a project will stay the same. Thus sprints, which live in the `Module` field, must be updated regularly. In order to facilitate that updating, instead of requiring users to get those IDs directly from the TimeTask website every time, have them use this command to get the names of sprints and their IDs. They can then update the ID manually in their config file. This code makes a request to the endpoint that returns module IDs for the site (the site queries this via AJAX to update its interface). The result of the request is some XML containing the modules and their IDs. For now I'm just printing this out. We'll want to parse the XML and display it in a nicer way.
2017-06-03Update TODOTeddy Wing
2017-06-03Merge branch 'handle-failing-responses-from-the-server' into timetasker-dailyTeddy Wing
2017-06-03Update TODOTeddy Wing
2017-06-03main(): Handle errors from HTTP responsesTeddy Wing
Add some simple error handling for known responses from our TimeTask HTTP requests. Check a couple of known strings to determine whether there was an error. If so, exit with a failing error code. Remove our old `log` statements. These were used during debugging to see some output and check responses from TimeTask. We now have an idea of what those responses are, and are handling some of the error cases. Thus the log statements are no longer needed.
2017-06-03main(): Add comment explaining `--project` validationTeddy Wing
2017-06-03main(): Change Kingpin error messages to lowercaseTeddy Wing
Remove the initial cap on Kingpin error messages for consistency in our messages.
2017-06-03Update TODOTeddy Wing
2017-06-03Merge branch 'load-from-xdg-config' into timetasker-dailyTeddy Wing
2017-06-03main(): Move `loadConfig()` call after CLI argument parsingTeddy Wing
Otherwise, if users haven't created a config file and they run `--help`, they'll get an error complaining that the config file doesn't exist instead of helpful usage output.
2017-06-03main(): Update error message for `loadConfig()` errorTeddy Wing
* Change the initial capital to lowercase for consistency with the other error messages * Suggest using `--write-config` as a possible solution to the error (in cases where the config file doesn't exist)
2017-06-03loadConfig(): Load from real XDG configTeddy Wing
Instead of loading the config file I've been testing with in the local project directory, load the real one from XDG_CONFIG_HOME.
2017-06-03Update TODOTeddy Wing
2017-06-03Merge branch 'password-cmd' into timetasker-dailyTeddy Wing
2017-06-03Make the `password_cmd` config setting workTeddy Wing
Given a string from `password_cmd`, we should execute it as a shell command and assume the result is a password. That password then gets submitted to TimeTask's login form for authentication. Had to do a bit of wrangling to get the command to execute by `exec.Command()`, but managed to get it working in a bit of a roundabout way. Found these resources in my searches: - https://stackoverflow.com/questions/39930109/golang-execute-command#39930127 https://stackoverflow.com/questions/28783637/how-to-make-golang-execute-a-string - https://stackoverflow.com/questions/20437336/how-to-execute-system-command-in-golang-with-unknown-arguments - https://github.com/codeskyblue/go-sh
2017-06-03main.go: Fix whitespaceTeddy Wing
Thanks gofmt
2017-06-03Merge branch 'use-kingpin-error-helpers' into timetasker-dailyTeddy Wing
2017-06-03Update TODOTeddy Wing
2017-06-03Merge branch 'config-initialiser' into timetasker-dailyTeddy Wing
2017-06-03main(): Change error handling to use Kingpin error helpersTeddy Wing
In order to maintain a consistent format when echoing error messages, use the Kingpin helpers to do so. Rewrite our error message code to this effect. This has the added benefit of making our code shorter.
2017-06-03main.go: Custom `Required()` for `--project` argumentTeddy Wing
As far as I've been able to figure out, Kingpin doesn't have a mechanism for dependent arguments or conditional requireds. Thus there's no way to say "--position is only required if --write-config isn't passed". In that case, write our own "required" check, to enforce the presence of "--project" only if "--write-config" isn't passed. We duplicate the message that Kingpin provides from `Required()` and leverage its error formatting (we should probably use this for our other error messages too). The only difference is that `--position=POSITION` won't appear on the first line of the Help text, which would have emphasised the fact that it's required. It's possible to configure Kingpin's help text via templates, but I don't think that's worth the trouble at this point.
2017-06-03main.go: If `--write-config` is passed, do work and exitTeddy Wing
Ensure that we're not actually submitting a time entry if the `--write-config` flag was passed. In that case, we just want to write the empty config file and exit successfully.
2017-06-03main.go: Only call `maybeWriteConfig()` when `--write-config` is givenTeddy Wing
We shouldn't automatically force writing the config file. Only do so if the user asks for it to be done. NOTE: there's a problem here, because `-p` is required but it shouldn't be in this specific case.
2017-06-03config.go: Extract config file paths to functionsTeddy Wing
Put these constructed paths into reusable functions for easier usage.
2017-06-03main.go: Handle errors coming from `loadConfig()`Teddy Wing
2017-06-03Make `MaybeWriteConfig()` a private functionTeddy Wing
I figured it would be a good idea to make this function and `loadConfig()` consistent. Since `loadConfig()` is private, make this one private also.
2017-06-03Move `Config` & `loadConfig()` to config.goTeddy Wing
Now that we have a 'config.go' file, it makes more sense for these two to live in that file. Change `loadConfig()` to return an error instead of printing it to the log.
2017-06-03main.go: Handle errors from MaybeWriteConfig()Teddy Wing
If the function results in an error, print it and exit.
2017-06-03MaybeWriteConfig(): Write an empty config fileTeddy Wing
If no existing config file is found, write a sample config file to XDG_CONFIG_HOME/timetasker/config.toml.
2017-06-03Add `MaybeWriteConfig()`Teddy Wing
A new function that will write a new config.toml file to the XDG_CONFIG_HOME directory. Currently it checks to see whether our config file is present. If not and our config directory isn't present, it creates it. Still need to get this to actually write the config file. Also, we won't want to call it by default in main() like we're doing now. Will likely want to hide it behind a `--write-config` flag.
2017-06-03Update TODOTeddy Wing
2017-06-03Merge branch 'fix-time-format-bug' into timetasker-dailyTeddy Wing
2017-06-03buildSubmissionParams(): Fix time string replacement bugTeddy Wing
We ran into a bug where submitting "7" as the time spent would become "700" on the site. This was because our `n` value of 0 wasn't replacing the "." in the string. Thus "7.00" became "7.00" after the replacement. Not right. I misunderstood what that argument was doing and what the word "empty" in the documentation meant. Change the `n` value to replace all "."s in the string.
2017-06-03Update TODOTeddy Wing
2017-06-03main.go: Run goimportsTeddy Wing
2017-06-03Update TODOTeddy Wing
2017-06-03Update TODOTeddy Wing
2017-06-03Merge branch 'command-line-arguments' into timetasker-dailyTeddy Wing
2017-06-03main.go: Move version string to `VERSION` variableTeddy Wing
Didn't really like having the application version intermixed with regular code. This separates it and makes it easier to see.
2017-06-03Change `TimeEntry.Time` to a `float64`Teddy Wing
I had forgotten that time spent can be a decimal. Make this field a float and change related code accordingly: * --time flag * `NewTimeEntry()` `time` argument * `buildSubmissionParams()` can't use `strconv.Itoa` as that's an integer function. Instead we use `FormatFloat`. Truncate time parsing to two decimal places because to me that seems like enough. Who's going to say they spent `0.324` hours on something? Also, in order to be able to properly submit values to TimeTask (at least on the edition I use), the times must be written in European/French format, with commas (`,`) as decimal separators. Do a string replace to get this, as the float formatter will give us a period (`.`) separator.
2017-06-03main.go: Handle the `--date` argumentTeddy Wing
If no date is passed in, default to the current date. Otherwise, parse the date into a time that can be used to create the `TimeEntry`. * Rename `date` to `date_str` to allow us to use `date` for the `time.Time` that gets sent to `NewTimeEntry()`. * If parsing fails, print an error message and exit. * In order to use the `err` variable without redefining `date` on line 66, define it at the top of the function.
2017-06-03main.go: Add a short version of the --date argumentTeddy Wing
Forgot to do this in 8d802bff08826523371ab5e951d85d0c0396ccc8. Also, the reason why I made --description's short form `-m` is because I wanted `-d` for date. The `-m` is supposed to be like "message", like in git-commit.
2017-06-03main.go: Fail if an unrecognised project alias is passedTeddy Wing
If the user specifies a project alias that doesn't exist in their config.toml file, we should fail early and message the user about it.
2017-06-03main.go: Create time entry before making HTTP requestsTeddy Wing
Make it easier to comment out the HTTP requests when testing command line argument parsing. To test, we're just printing the time entry with: log.Printf("%+v\n", time_entry) Fill in the values from our new command line argument variables. These need to be dereferenced as they come out of Kingpin as pointers. Haven't completely worked out how to deal with the 'date' argument yet so leaving it for later. Need to fail early if `project_alias` isn't recorgnised.
2017-06-03Add command line argument parsingTeddy Wing
* Use the Kingpin library to give us POSIX command line argument parsing with a nice interface * Add arguments for the project alias (specified in config.toml), time spent, date, and description * Add a version, required by Kingpin
2017-06-03Add TODOTeddy Wing
Make a note of the things I have in my head right now that I think need to be done to get this project from a "works" state into a "usable" state.
2017-06-03Merge branch 'cleanup-from-single-time-entry-submission-work' into ↵Teddy Wing
timetasker-daily
2017-06-03main.go: Remove old commented codeTeddy Wing
This code was used for the old multiple time entry submission version of this program. Remove it now that the program only submits single time entries. We'll have similar argument handling code for user data, and the time entry submission code is already present here.