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

Introduce an initial attempt at a CLI #113

Merged
merged 11 commits into from
Dec 30, 2023
45 changes: 35 additions & 10 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,26 @@ jobs:
npm install -g npm
node version.js "v${{ steps.normalise_version.outputs.version }}"
cd frontend && npm install


# Build -- cli variants

## We skip Windows Portable for now because files have no consistent home and that's more weirdness than I want to deal with at the moment
## We skip Darwin Universal because there is no build target for Go (that I am aware of!)
- name: Build october-cli
if: ${{ matrix.build.tag != 'windows-portable_amd64' && matrix.build.tag != 'darwin_universal' }}
shell: bash
run: GOOS=$(echo ${{ matrix.build.platform }} | cut -d '/' -f 1) GOARCH=$(echo ${{ matrix.build.platform }} | cut -d '/' -f 2) go build -ldflags="-X main.version=v${{ steps.normalise_version.outputs.version }}"
working-directory: ./cmd/october-cli

# Windows
- name: Move october-cli inside windows asset folder
if: runner.os == 'Windows' && matrix.build.tag == 'windows_amd64'
shell: bash
run: mv cmd/october-cli/october-cli.exe build/windows

# Build -- app variants

## Linux
## Linux + macOS
- name: Build wails app for Linux / macOS
if: runner.os == 'Linux' || runner.os == 'macOS'
shell: bash
Expand All @@ -130,7 +146,11 @@ jobs:

# Codesigning (only performed when releases are cut)

## macOS
- name: Move october-cli inside October.app
if: ${{ runner.os == 'macOS' && matrix.build.tag != 'darwin_universal' }}
shell: bash
run: mv cmd/october-cli/october-cli build/bin/October.app/Contents/MacOS

- name: Notarise macOS app + create dmg
if: runner.os == 'macOS' && startsWith(github.ref, 'refs/tags/')
shell: bash
Expand All @@ -141,25 +161,29 @@ jobs:
AC_PROVIDER: "6RNEAKRYDT"

## Windows
- name: Codesign Windows NSIS Installer
- name: Codesign Windows CLI
if: runner.os == 'Windows' && matrix.build.tag == 'windows_amd64' && startsWith(github.ref, 'refs/tags/')
run: |
echo "Creating certificate file"
New-Item -ItemType directory -Path certificate
Set-Content -Path certificate\certificate.txt -Value '${{ secrets.WIN_SIGNING_CERT }}'
certutil -decode certificate\certificate.txt certificate\certificate.pfx
echo "Signing October installer"
### Set up certificates
- name: Codesign Windows CLI
if: runner.os == 'Windows' && matrix.build.tag == 'windows_amd64' && startsWith(github.ref, 'refs/tags/')
run: |
& 'C:/Program Files (x86)/Windows Kits/10/bin/10.0.17763.0/x86/signtool.exe' sign /fd sha256 /tr http://ts.ssl.com /f certificate\certificate.pfx /p '${{ secrets.WIN_SIGNING_CERT_PASSWORD }}' october-cli.exe
working-directory: ./build/bin

- name: Codesign Windows NSIS Installer
if: runner.os == 'Windows' && matrix.build.tag == 'windows_amd64' && startsWith(github.ref, 'refs/tags/')
run: |
& 'C:/Program Files (x86)/Windows Kits/10/bin/10.0.17763.0/x86/signtool.exe' sign /fd sha256 /tr http://ts.ssl.com /f certificate\certificate.pfx /p '${{ secrets.WIN_SIGNING_CERT_PASSWORD }}' October-${{ matrix.build.arch }}-installer.exe
working-directory: ./build/bin

- name: Codesign Windows Portable
if: runner.os == 'Windows' && matrix.build.portable == 'windows-portable_amd64' && startsWith(github.ref, 'refs/tags/')
run: |
echo "Creating certificate file"
New-Item -ItemType directory -Path certificate
Set-Content -Path certificate\certificate.txt -Value '${{ secrets.WIN_SIGNING_CERT }}'
certutil -decode certificate\certificate.txt certificate\certificate.pfx
echo "Signing October installer"
& 'C:/Program Files (x86)/Windows Kits/10/bin/10.0.17763.0/x86/signtool.exe' sign /fd sha256 /tr http://ts.ssl.com /f certificate\certificate.pfx /p '${{ secrets.WIN_SIGNING_CERT_PASSWORD }}' october.exe
working-directory: ./build/bin

Expand All @@ -171,6 +195,7 @@ jobs:
shell: bash
run: |
mv build/bin/october build/linux/october_0.0.0_ARCH/usr/local/bin/
mv cmd/october-cli/october-cli build/linux/october_0.0.0_ARCH/usr/local/bin/
cd build/linux
sed -i 's/0.0.0/${{ steps.normalise_version.outputs.version }}/g' "october_0.0.0_ARCH/DEBIAN/control"
sed -i 's/ARCH/${{ matrix.build.arch }}/g' "october_0.0.0_ARCH/DEBIAN/control"
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ site
frontend/dist/*
!frontend/dist/.gitkeep
build/linux/*.deb
build/linux/october_0.0.0_amd64/usr/local/bin/october
build/linux/october_0.0.0_amd64/usr/local/bin/october
build/linux/october_0.0.0_amd64/usr/local/bin/october-cli
cmd/october-cli/october-cli
1 change: 0 additions & 1 deletion backend/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ func (b *Backend) NavigateExplorerToLogLocation() {

func (b *Backend) DetectKobos() []Kobo {
connectedKobos, err := kobo.Find()
logrus.WithField("kobos_found", len(connectedKobos)).Info("Detected one or more Kobos")
if err != nil {
panic(err)
}
Expand Down
73 changes: 73 additions & 0 deletions cmd/october-cli/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package main

import (
"context"
"fmt"
"log"
"os"
"strconv"

"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"

"github.com/marcus-crane/october/backend"
)

var (
version = "DEV"
portablebuild = "false"
)

func main() {
isPortable := false
isPortable, _ = strconv.ParseBool(portablebuild)

app := &cli.App{
Name: "october",
HelpName: "october-cli",
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: "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)
}
}
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ require (
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.0
github.com/stretchr/testify v1.8.1
github.com/urfave/cli/v2 v2.27.0
github.com/wailsapp/wails/v2 v2.7.1
gorm.io/gorm v1.25.5
)

require (
github.com/bep/debounce v1.2.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/glebarez/go-sqlite v1.21.2 // indirect
Expand All @@ -39,12 +41,14 @@ require (
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rogpeppe/go-internal v1.8.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/samber/lo v1.38.1 // indirect
github.com/tkrajina/go-reflector v0.5.6 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/wailsapp/go-webview2 v1.0.10 // indirect
github.com/wailsapp/mimetype v1.4.1 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
golang.org/x/net v0.17.0 // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls=
github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E=
github.com/bep/debounce v1.2.1 h1:v67fRdBA9UQu2NhLFXrSg0Brw7CexQekrBwDMM8bzeY=
github.com/bep/debounce v1.2.1/go.mod h1:H8yggRPQKLUhUoqrJC1bO2xNya7vanpDl7xR3ISbCJ0=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -73,6 +75,8 @@ github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg=
github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM=
github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
Expand All @@ -88,6 +92,8 @@ github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKs
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/tkrajina/go-reflector v0.5.6 h1:hKQ0gyocG7vgMD2M3dRlYN6WBBOmdoOzJ6njQSepKdE=
github.com/tkrajina/go-reflector v0.5.6/go.mod h1:ECbqLgccecY5kPmPmXg1MrHW585yMcDkVl6IvJe64T4=
github.com/urfave/cli/v2 v2.27.0 h1:uNs1K8JwTFL84X68j5Fjny6hfANh9nTlJ6dRtZAFAHY=
github.com/urfave/cli/v2 v2.27.0/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
Expand All @@ -99,6 +105,8 @@ github.com/wailsapp/mimetype v1.4.1 h1:pQN9ycO7uo4vsUUuPeHEYoUkLVkaRntMnHJxVwYhw
github.com/wailsapp/mimetype v1.4.1/go.mod h1:9aV5k31bBOv5z6u+QP8TltzvNGJPmNJD4XlAL3U+j3o=
github.com/wailsapp/wails/v2 v2.7.1 h1:HAzp2c5ODOzsLC6ZMDVtNOB72ozM7/SJecJPB2Ur+UU=
github.com/wailsapp/wails/v2 v2.7.1/go.mod h1:oIJVwwso5fdOgprBYWXBBqtx6PaSvxg8/KTQHNGkadc=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc=
Expand Down
Loading