Skip to content

Commit fcefbf5

Browse files
committed
fix cli application
1 parent 7ce1e42 commit fcefbf5

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

cmd/cli/cmd_add.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,30 +46,30 @@ func addCmdRun(cmd *cobra.Command, args []string) {
4646
name := cmd.Flag("name").Value.String()
4747

4848
// Try to read the file to see if we can find headers
49-
s, err := scriptLib.ReadFile(args[0])
49+
scr, err := scriptLib.ReadFile(args[0])
5050
if err != nil {
5151
cmd.PrintErrf("failed to read the script file %s: %v", args[0], err)
5252
return
5353
}
5454
if subject == "" {
55-
if s.Subject == "" {
55+
if scr.Subject == "" {
5656
cmd.PrintErrf("subject is required")
5757
return
5858
}
5959

60-
subject = s.Subject
60+
subject = scr.Subject
6161
}
6262
if name == "" {
63-
if s.Name == "" {
63+
if scr.Name == "" {
6464
cmd.PrintErrf("name is required")
6565
return
6666
}
6767

68-
name = s.Name
68+
name = scr.Name
6969
}
7070

7171
// Add the script to etcd under the given subject
72-
err = scriptStore.AddScript(cmd.Context(), subject, name, s.Content)
72+
err = scriptStore.AddScript(cmd.Context(), subject, name, scr)
7373
if err != nil {
7474
cmd.PrintErrf("Failed to add script to etcd: %v", err)
7575
return

cmd/cli/cmd_dev.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,31 +53,31 @@ func devCmdRun(cmd *cobra.Command, args []string) {
5353
name := cmd.Flag("name").Value.String()
5454

5555
// Try to read the file to see if we can find headers
56-
s, err := scriptLib.ReadFile(args[0])
56+
scr, err := scriptLib.ReadFile(args[0])
5757
if err != nil {
5858
log.Errorf("failed to read the script file %s: %v\n", args[0], err)
5959
return
6060
}
6161

6262
if subject == "" {
63-
if s.Subject == "" {
63+
if scr.Subject == "" {
6464
cmd.PrintErrf("subject is required\n")
6565
return
6666
}
6767

68-
subject = s.Subject
68+
subject = scr.Subject
6969
}
7070
if name == "" {
71-
if s.Name == "" {
71+
if scr.Name == "" {
7272
cmd.PrintErrf("name is required\n")
7373
return
7474
}
7575

76-
name = s.Name
76+
name = scr.Name
7777
}
7878

7979
// Add the given script to the store
80-
err = store.AddScript(cmd.Context(), subject, name, s.Content)
80+
err = store.AddScript(cmd.Context(), subject, name, scr)
8181
if err != nil {
8282
cmd.PrintErrf("failed to add script to store: %v\n", err)
8383
return

cmd/cli/cmd_devhttp.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616

1717
"github.com/numkem/msgscript/executor"
1818
msgplugin "github.com/numkem/msgscript/plugins"
19+
"github.com/numkem/msgscript/script"
1920
scriptLib "github.com/numkem/msgscript/script"
2021
"github.com/numkem/msgscript/store"
2122
)
@@ -152,15 +153,16 @@ func (p *devHttpProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
152153
}
153154

154155
// Add only the currently worked on file
155-
b, err := os.ReadFile(p.scriptFile)
156+
scr, err := script.ReadFile(p.scriptFile)
156157
if err != nil {
157158
e := fmt.Errorf("failed to read script file %s: %w", p.scriptFile, err)
158159
log.Error(e.Error())
159160
w.WriteHeader(http.StatusInternalServerError)
160161
w.Write([]byte(e.Error()))
161162
return
162163
}
163-
p.store.AddScript(p.context, s.Subject, s.Name, b)
164+
165+
p.store.AddScript(p.context, s.Subject, s.Name, scr)
164166

165167
// Create a new empty store at the end of each request
166168
defer emptyStore(p.store, p.libraryDir)

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
outputs =
99
{ self, nixpkgs }:
1010
let
11-
version = "0.6.0";
11+
version = "0.6.2";
1212
vendorHash = "sha256-LcgdJIsn3/fHv3NGvGdfq/Y3N7CTuIH/b5Rv5tEMUg8=";
1313

1414
mkPlugin =

0 commit comments

Comments
 (0)