-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Marcus Crane <marcus@utf9k.net>
- Loading branch information
1 parent
51b7e10
commit a571a44
Showing
4 changed files
with
113 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package cli | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/marcus-crane/october/backend" | ||
"github.com/mattn/go-isatty" | ||
"github.com/sirupsen/logrus" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func IsInvokedFromTerminal() bool { | ||
if isatty.IsTerminal(os.Stdout.Fd()) { | ||
return true | ||
} | ||
if isatty.IsCygwinTerminal(os.Stdout.Fd()) { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
func Invoke(isPortable bool, version string) { | ||
app := &cli.App{ | ||
Name: "october", | ||
HelpName: "october", | ||
Version: version, | ||
Authors: []*cli.Author{ | ||
{ | ||
Name: "Marcus Crane", | ||
Email: "october@utf9k.net", | ||
}, | ||
}, | ||
Usage: "sync your kobo highlights to readwise from your terminal", | ||
Commands: []*cli.Command{ | ||
{ | ||
Name: "launch", | ||
Usage: "skip cli tool and launch desktop ui", | ||
}, | ||
{ | ||
Name: "sync", | ||
Aliases: []string{"s"}, | ||
Usage: "sync kobo highlights to readwise", | ||
Action: func(c *cli.Context) error { | ||
ctx := context.Background() | ||
b := backend.StartBackend(&ctx, version, isPortable) | ||
if b.Settings.ReadwiseToken == "" { | ||
return fmt.Errorf("no readwise token was configured. please set this up using the gui as the cli does not support this yet") | ||
} | ||
kobos := b.DetectKobos() | ||
if len(kobos) == 0 { | ||
return fmt.Errorf("no kobo was found. have you plugged one in and accepted the connection request?") | ||
} | ||
if len(kobos) > 1 { | ||
return fmt.Errorf("cli only supports one connected kobo at a time") | ||
} | ||
err := b.SelectKobo(kobos[0].MntPath) | ||
if err != nil { | ||
return fmt.Errorf("an error occurred trying to connect to the kobo at %s", kobos[0].MntPath) | ||
} | ||
num, err := b.ForwardToReadwise() | ||
if err != nil { | ||
return err | ||
} | ||
logrus.Infof("Successfully synced %d highlights to Readwise", num) | ||
return nil | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
err := app.Run(os.Args) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters