writeas / writeas-cli

Command line client for Write.as / WriteFreely
https://write.as/apps/cli
GNU General Public License v3.0
113 stars 20 forks source link

ref T586 support any writefreely instance #36

Closed ghost closed 4 years ago

ghost commented 5 years ago

This one is a bit huge.

First this creates a new binary wf which supports additional features not needed on write.as. Namely different hosts and multiple users, as many user accounts can be authenticated as you wish. Just pass a -u <username> global flag to select the one to use for an action. i.e. wf -u rob posts

This would be v1.0 for wf.

ref T592, T593, T594, T595, T597, T634, T635, T645

ghost commented 5 years ago

also will need to verify the change with global flags doesn't break anything fixed

ghost commented 5 years ago

found a small bug I missed, unsynced posts are stored in one file at the root, not at each host level. fix incoming.

ghost commented 5 years ago

just waiting for writeas/go-writeas#18 to verify things work as expected

ghost commented 5 years ago

updated, but I need to make a change for custom tor url now

thebaer commented 5 years ago

Still need to do some more exhaustive testing, but I think most of what I found is fixed. Biggest behavior changes:

Also, in building this I found a bug in WF where the instance's full URL isn't returned in the API. This is fixed in writeas/writefreely#144, so wf-cli will only work with an instance at WF v0.11 or later.

thebaer commented 5 years ago

Another thing I'd like to fix: when running e.g. wf --host team.write.as logout (i.e. with a --host but not --user) the error message just says I'm not logged in and need to authenticate.

If I am authenticated as a single user on that instance, I'd like it to know that and just use the account.

If I'm authenticated as multiple users on that instance, I'd like it to inform me that I need to supply the -u / --user flag.

ghost commented 5 years ago

@thebaer do you want me to finish this up?

thebaer commented 5 years ago

Yep, that'd be great. Just to add to my last comment, I'd like to see that behavior on all commands, not just logout

ghost commented 5 years ago

ready for final testing and review @thebaer

thebaer commented 4 years ago

Okay, we're getting very close. This may be the last issue we need to solve. The situation is:

I'm logged in under multiple accounts, but don't have a default user set (I logged out of it, so it was removed from the config). Now when I run ./wf I get:

You must be authenticated to publish.
Log in first with: wf auth <username>

This is confusing, because I am authenticated -- wf just doesn't know what account to use, since there's no default and no flags given. So instead, I'd like it to say something like:

You are authenticated, but have no default user set. Supply -user and -host flags.

I started trying to implement this, but it looks like it's going to need a bit more work. It looks like we're getting very close to needing the accounts command. If that logic is needed to get this error message, then we should do it.

What do you think?

ghost commented 4 years ago

I'll take a look quick, we might be able to get this without adding the accounts command, then add that after. Unless you want it all in for the CLI release.

thebaer commented 4 years ago

Let's try to go without it for this initial release and add it later.

ghost commented 4 years ago

ok got it, just going to clean up some redundancy quick

ghost commented 4 years ago

I didn't bother to refactor, it would only save three lines in two places.

thebaer commented 4 years ago

Awesome, will test when I'm back at my computer.

thebaer commented 4 years ago

Just tested latest changes and now I'm unable to post anything:

$ echo "hi" | ./wf -host team.write.as
Unable to post: Problem creating post: 401. Not logged in.
$ echo "hi" | ./wf -host team.write.as -user matt
Unable to post: Problem creating post: 401. Not logged in.

To be sure, I'm authenticated as matt on team.write.as. Is everything working for you?

thebaer commented 4 years ago

Also some odd behavior when I do have a default account:

$ ./wf -host pencil.writefree.ly auth hello
Password: *******
Set hello on pencil.writefree.ly as default account.
$ echo "hi" | ./wf
Error creating data directory: mkdir /home/mattbaer/.writefreely/https:/pencil.writefree.ly: no such file or directory
You must be authenticated to publish.
Log in first with: wf auth <username>

Probably because we store the schema in the configuration. Which is probably correct, e.g. if someone logs in with the --insecure flag we should respect that. But then when loading the default from the config file, we shouldn't prepend any schema. Could you take a look at that?

thebaer commented 4 years ago

Looks really, really good!

I think the very last thing is that we should undo the change where wf automatically posts to the logged in user's default collection (i.e. the one that matches their username). It's convenient, but it makes publishing drafts impossible, so we should fix that.

I also fixed some weird language when trying to run commands while being unauthenticated.

ghost commented 4 years ago

Sure, I can revert the default collection thing.

thebaer commented 4 years ago

Great. Though now I don't seem to be able to post at all:

Unable to post: Problem creating post: 401. Not logged in.
ghost commented 4 years ago

silly question, are you logged in? I tried with both wf and writeas with success. using the default command, and new. which sub command are you using?

thebaer commented 4 years ago

Hmm yeah, I authenticated right after I pulled in those changes. But then I re-authenticated with the same exact account and now it's all working. Weird. But draft publishing works :+1:

Doing one last run-through and then we'll merge!

thebaer commented 4 years ago

There are still some very small places where we can improve the UX, but we can address them in the next update. Great work! Merging now.