Age | Commit message (Collapse) | Author |
|
|
|
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.
|
|
* 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)
|
|
Instead of loading the config file I've been testing with in the local
project directory, load the real one from XDG_CONFIG_HOME.
|
|
|
|
|
|
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
|
|
Thanks gofmt
|
|
|
|
|
|
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
Put these constructed paths into reusable functions for easier usage.
|
|
|
|
I figured it would be a good idea to make this function and
`loadConfig()` consistent. Since `loadConfig()` is private, make this
one private also.
|
|
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.
|
|
If the function results in an error, print it and exit.
|
|
If no existing config file is found, write a sample config file to
XDG_CONFIG_HOME/timetasker/config.toml.
|
|
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.
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
|
|
Didn't really like having the application version intermixed with
regular code. This separates it and makes it easier to see.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
* 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
|
|
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.
|
|
timetasker-daily
|
|
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.
|
|
|
|
|
|
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'.
|
|
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.
|
|
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.
|
|
|
|
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'.)
|
|
This field wasn't parsing correctly because of it's
non-automatically-parseable format.
|
|
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.
|
|
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
|