aboutsummaryrefslogtreecommitdiffstats
AgeCommit message (Collapse)Author
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.
2017-06-03main.go;http.go: Remove commented unused importsTeddy Wing
2017-06-03Run gofmt on all project filesTeddy Wing
2017-06-03Move 'fields.go' to 'project.go'Teddy Wing
Get rid of all the old commented Fields code. It's no longer used and is no longer relevant. Furthermore, since the only thing left in this file is the `Project` struct, rename the file to 'project.go'.
2017-06-03Remove generator.go, templates/ directoryTeddy Wing
These are not needed in the new world where we only submit a single time entry at a time and entry parameters are filled in on the command line. My guess is we'll likely have some sort of generator in the future to create the initial `config.toml` file, but that won't contain any logic-based data. My guess is we'll probably be able to just stick it in a template string right inside a *.go file.
2017-06-03http_test.go: Skip Login() testTeddy Wing
Because it makes a network request. I originally wrote this to test the Login function while developing so it wasn't a big deal, but we really don't want to run this type of test in normal situations.
2017-06-03Merge branch 'submit-single-time-entry' into timetasker-dailyTeddy Wing
2017-06-03buildSubmissionParams(): Add `f_entryIndexes` paramTeddy Wing
The param needs to be present in the request in order for it to be considered. Add it back in (we had it before 810b140b4a29b1159e76b51b90b9be7d22df1c3e) with only the `0` index being sent in the request. This is because we're only submitting a single time entry, the 0th one. (Other parameters end with a '0'.)
2017-06-03main.go: Add TOML tag to Config.PasswordCmdTeddy Wing
This field wasn't parsing correctly because of it's non-automatically-parseable format.
2017-06-03main.go: Print HTTP response bodies for debuggingTeddy Wing
Previously we were just printing the headers. Now print the bodies to allow us to inspect the result. Will probably want to add some handling that messages the user about authentication problems.
2017-06-03Initial stab at submitting time entries for realTeddy Wing
main.go: * Login as the configured user (haven't yet handled making `PasswordCmd` an actual shell command) * Create a test time entry * Submit that time entry using `SubmitTimeEntry()` http.go: * Create a `baseURL` global that stores the base TimeTask URL to make requests to * Return an `http.Client` from `Login()` that can then be passed to `SubmitTimeEntry()` to reuse the login session. Needed to return a pointer to allow us to return `nil` from the first error handler in the function. Don't like that at all, but we're just trying to get it to work at this point. * Actually make an HTTP POST request in `SubmitTimeEntry()` using the given HTTP Client and existing time entry submission params * Take an `http.Client` argument in `SubmitTimeEntry()` to allow us to use a logged-in session to POST. Otherwise we'd be locked out. * Change `v` variable to `values` in `SubmitTimeEntry()` for better readability