Skip to content

Commit 87f8c50

Browse files
committed
feat: v0.6.3
1 parent 74194d4 commit 87f8c50

File tree

12 files changed

+63
-48
lines changed

12 files changed

+63
-48
lines changed

internal/cmd/cast.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,12 @@ func castInline(s *library.Scroll) error {
100100
}
101101

102102
func castFile(s *library.Scroll, path string) error {
103-
args := []string{s.Library().ConfigDir()}
104103
ex := s.Exec()
104+
args := []string{}
105+
106+
if len(ex.Args) > 0 {
107+
args = append(args, ex.Args...)
108+
}
105109

106110
if ex.AlwaysUseArgs {
107111
args = append(ex.Args, path)

internal/cmd/list.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ var listCmd = &cobra.Command{
3838
return
3939
}
4040

41+
if len(list) == 0 {
42+
fmt.Println("No scrolls found.")
43+
return
44+
}
45+
4146
action := ""
4247
form := huh.NewSelect[string]().
4348
Title(fmt.Sprintf("Selected Scroll: %s", selection.Name())).

internal/library/library.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ func (l *Library) Migrate() error {
6565

6666
// do we have a db connection still?
6767
fmt.Printf("\n\nFailed to run migrations: failed to backup sqlite db.\n")
68-
fmt.Printf("You can force the migration without backing up using --skip-backup, however please manually backup your scrolls db first.\n")
68+
fmt.Printf("Please manually backup your scrolls db.\n")
6969
fmt.Printf("DB location: %s\n", l.dbLocation)
70-
fmt.Printf("Then run: scrolls --skip-backup\n\n")
70+
fmt.Printf("Then run: scrolls to attempt another migration.\n\n")
7171
return nil
7272
}
7373

internal/library/migrations/migrate.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,8 @@ func rollback(db *sql.DB) func(shared.MigrationInterface) error {
103103
DELETE FROM
104104
migrations
105105
WHERE
106-
name = ?
107-
LIMIT 1
108-
`, m.Name())
106+
migration = ?`,
107+
m.Name())
109108

110109
return err
111110
}

internal/library/migrations/shared/migration.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ func (m *Migration) DownSQL() string {
2727
}
2828

2929
func (m *Migration) Up(db *sql.DB, migrate func(MigrationInterface) error) error {
30-
err := migrate(m)
31-
if err != nil {
32-
return nil
30+
if err := migrate(m); err != nil {
31+
return err
3332
}
3433

3534
if m.up != nil {

internal/scrolls/client.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,14 @@ func (c *Client) newRequest(method, endpoint string, body io.Reader) (*http.Requ
6666
return nil, err
6767
}
6868

69-
url, err = url.Parse(endpoint)
69+
rel, err := url.Parse(endpoint)
7070
if err != nil {
7171
return nil, err
7272
}
7373

74-
req, err := http.NewRequest(method, url.String(), body)
74+
full := url.ResolveReference(rel)
75+
76+
req, err := http.NewRequest(method, full.String(), body)
7577
if err != nil {
7678
return nil, err
7779
}

internal/scrolls/storage.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package scrolls
33
import (
44
"bufio"
55
"bytes"
6-
"errors"
76
"fmt"
87
"log"
98
"os"
@@ -69,7 +68,7 @@ func (c *StorageClient) New(name string, useTemplate bool, fromFile string) (*li
6968
if fromFile != "" {
7069
ffbyte, err := os.ReadFile(fromFile)
7170
if err != nil {
72-
return nil, errors.New("failed to read the content of \"%s\"; is the path correct?")
71+
return nil, fmt.Errorf("failed to read the content of %q; is the path correct?", fromFile)
7372
}
7473

7574
templateContent = ffbyte
@@ -166,7 +165,7 @@ func (c *StorageClient) editFile(f *FileHandler, scroll *library.Scroll) (*FileH
166165
cmd.Stdout = os.Stdout
167166
cmd.Stderr = os.Stderr
168167

169-
log.Printf("opening in: %s, waiting to editor to close before proceeding..\n", bin)
168+
log.Printf("opening in: %s, waiting for editor to close before proceeding..\n", bin)
170169

171170
now := time.Now().Add(time.Second * time.Duration(2)).Unix()
172171
err := cmd.Run()
@@ -176,27 +175,28 @@ func (c *StorageClient) editFile(f *FileHandler, scroll *library.Scroll) (*FileH
176175
}
177176

178177
end := time.Now().Unix()
179-
178+
isQuick := end <= now
180179
if flags.Debug() {
181-
fmt.Printf("opening in external editor \"%s\": %t\n", bin, now > end)
180+
fmt.Printf("editor %q exited quickly: %t\n", bin, isQuick)
182181
}
183182

184-
if now > end {
183+
if isQuick {
185184
fmt.Println("When you are done, Press Enter to continue..")
186-
bufio.NewReader(os.Stdin).ReadString('\n')
185+
_, _ = bufio.NewReader(os.Stdin).ReadString('\n')
187186
}
188187

189188
_, err = f.Read()
190189
if err != nil {
191190
return f, err
192191
}
193192

193+
defer f.Delete()
194+
194195
if scroll != nil {
195196
if bytes.Equal(f.Body(), scroll.Body()) {
196197
return f, nil
197198
}
198199
}
199200

200-
f.Delete()
201201
return f, nil
202202
}

internal/settings/settings.go

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ func LoadSettings() (*Settings, error) {
7676
}
7777

7878
fmt.Printf("Warning: could not parse JSON config from file %s\n", configFile)
79-
fmt.Printf("Fix the syntax errors on the file, or use the --reset-config flag to replace it with a fresh one.\n")
80-
fmt.Printf("E.g. scrolls config init --reset-config\n")
79+
fmt.Printf("Fix the syntax errors in the file and try again..\n")
8180

8281
return nil, err
8382
default:
@@ -104,25 +103,32 @@ func (s *Settings) GetEditor() string {
104103
return e
105104
}
106105

107-
// defaults
108-
_, err := exec.LookPath("vim")
109-
if err == nil {
110-
return "vim"
106+
candidates := []string{
107+
"nvim",
108+
"vim",
109+
"vi",
110+
"nano",
111+
"emacs",
112+
"micro",
113+
"hx",
114+
"code",
115+
"zed",
116+
"subl",
117+
"sublime_text",
118+
"notepad++",
119+
"notepad",
120+
"gedit",
121+
"kate",
111122
}
112123

113-
_, err = exec.LookPath("vi")
114-
if err == nil {
115-
return "vi"
116-
}
117-
118-
_, err = exec.LookPath("zed")
119-
if err == nil {
120-
return "zed"
124+
for _, c := range candidates {
125+
if _, err := exec.LookPath(c); err == nil {
126+
return c
127+
}
121128
}
122129

123-
_, err = exec.LookPath("notepad")
124-
if err == nil {
125-
return "notepad"
130+
if e == "" {
131+
fmt.Fprintln(os.Stderr, "No editor configured and no default editor found on PATH")
126132
}
127133

128134
return ""

internal/tui/exec_selector.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
4242
}
4343

4444
case "ctrl+c":
45-
m.selection.cancel = true
45+
if m.selection != nil {
46+
m.selection.cancel = true
47+
}
4648
return m, tea.Quit
4749

4850
case "enter":
@@ -65,12 +67,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
6567
m.table, cmd = m.table.Update(msg)
6668
} else {
6769
m.input, cmd = m.input.Update(msg)
68-
6970
m.table.SetRows(filterRows(m.rows, m.input.Value()))
70-
tModel, tCmd := m.table.Update(msg)
71-
m.table = tModel
72-
73-
tea.Batch(cmd, tCmd)
7471
}
7572

7673
return m, cmd

internal/tui/scroll_list.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ func (m listModel) View() string {
5656
}
5757

5858
func NewScrollList(scrolls []*library.Scroll) (*library.Scroll, bool) {
59+
if len(scrolls) == 0 {
60+
fmt.Println("No scrolls found.")
61+
return nil, true
62+
}
63+
5964
columns := []table.Column{
6065
{Title: "Name", Width: 20},
6166
{Title: "Type", Width: 10},

0 commit comments

Comments
 (0)