Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the sync command #211

Merged
merged 3 commits into from
Aug 16, 2020
Merged

Update the sync command #211

merged 3 commits into from
Aug 16, 2020

Conversation

gammons
Copy link
Owner

@gammons gammons commented Aug 8, 2020

Previously, setting up a list to sync with ultralist.io was fairly convoluted. Bot the init and sync commands were dependent on a list's sync state, and the behavior of these commands would change based upon that.

Previous flow:

  • ultralist init - Create a new list and optionally, sync it with Ultralist.io.
  • ultralist sync - Depending if a list is synced or not, it does multiple things:
    • If not synced, sets up the local list to sync to ultralist.io.
    • If is already synced, pull remote changes to local, and push any local changes to remote.

This PR simplifies the commands by adding a couple of flags to the sync command. The result is that each command has one job to do, instead of many dependent on state. It's simpler to understand as well.

With this PR:

  • ultralist init - makes this command do just one thing - initialize a list. It does not handle syncing a list as well.
  • ultralist sync --setup - sets up a local list to sync with ultralist.io, or pulls a list from ultralist.io and replaces what's local.
  • ultralist sync --unsync - stops a local list from syncing with ultralist.io.
  • ultralist sync - just handles the actual list syncing between local and ultralist.io.

Previously, setting up a list to sync with ultralist.io was fairly convoluted.  Bot the `init` and `sync` commands were dependent on a list's sync state, and the behavior of these commands would change based upon that.

**Previous flow:**

* `ultralist init` - Create a new list and optionally, sync it with Ultralist.io.
* `ultralist sync` - Depending if a list is synced or not, it does multiple things:
  * If not synced, sets up the local list to sync to ultralist.io.
  * If is already synced, pull remote changes to local, and push any local changes to remote.

This PR simplifies the commands by adding a couple of flags to the `sync` command.  The result is that each command has one job to do, instead of many dependent on state.  It's simpler to understand as well.

**With this PR:**

* `ultralist init` - makes this command do just one thing - initialize a list.  It does not handle syncing a list as well.
* `ultralist sync --setup` - sets up a local list to sync with ultralist.io, or pulls a list from ultralist.io and replaces what's local.
* `ultralist sync --unsync` - stops a local list from syncing with ultralist.io.
* `ultralist sync` - just handles the actual list syncing between local and ultralist.io.
Copy link
Contributor

@stuartskelton stuartskelton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, and makes me want to start digging back into this Project, and may be see if I can build my own backend server...

}
}
// pull a list from ultralist.io
type Response struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be its me not being a full time golang programmer, but a struct, definition inside of a func seems a little odd (unless you are trying to hide it)

func (a *App) SetupSync() {
backend := NewBackend()
if !backend.CredsFileExists() {
fmt.Println("You're not authenticated with ultralist.io yet. Please run `ultralist auth` first.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this error isnt strictly true, it is only checking for if the file exists and could contain bad auth keys.

NewBackend(), already check and loads this file, so would a more correct test be.

    if backend.Credentials == "" {
		fmt.Println("You're not authenticated with ultralist.io yet.  Please run `ultralist auth` first.")
                 return
}

Side note: If you are using JWT (I dont have a UL account so I am guessing) as the authentication, should we also check to see it is valid before trying to use it? or as part of the loadCreds, or a new function checkCreds.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, that's a good catch!

Regarding the JWT, I don't feel strongly about validating, since the request would ultimately fail if they have invalid creds.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did try it with just using backend.Creds, and it didn't seem to work. idk 🤷

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try with a ~/.config/ultralist/cred.json with {}.

Also a blank file will cause a panic when NewBackend() tries to parse it.

I was thinking about turning those panics into a log and non-0 exit.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure there's a scenario where creds.json would have that info in it though.

also, refactor file_store so it is less rigid.
// FileStore is the main struct of this file.
type FileStore struct {
FileLocation string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing this breaks tests.

# github.com/ultralist/ultralist/ultralist [github.com/ultralist/ultralist/ultralist.test]
./file_store_test.go:13:22: unknown field 'FileLocation' in struct literal of type FileStore
./file_store_test.go:18:23: unknown field 'FileLocation' in struct literal of type FileStore
FAIL	github.com/ultralist/ultralist/ultralist [build failed]

Copy link
Owner Author

@gammons gammons Aug 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch!

// Returns if a local .todos.json file exists in the current dir.
func (f *FileStore) LocalTodosFileExists() bool {
dir, _ := os.Getwd()
localrepo := fmt.Sprintf("%s/.todos.json", dir)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would filepath.Join(dir, FILENAME) be more robust?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep it would.

@gammons
Copy link
Owner Author

gammons commented Aug 16, 2020

thanks for your review, @stuartskelton !

@gammons gammons merged commit ce9aa24 into main Aug 16, 2020
@gammons gammons deleted the init-sync branch August 16, 2020 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants