Skip to content

Commit a8713e1

Browse files
committed
Adding init config option
1 parent 28b1d0a commit a8713e1

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

run.go

+12-6
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func New(cliargs []string) ContextExecutor {
123123
if len(cliargs) > 0 {
124124
args.DSN = cliargs[0]
125125
}
126-
return Run(cmd.Context(), args, v.GetStringMap("connections"))
126+
return Run(cmd.Context(), args, v.GetStringMap("connections"), v.GetString("init"))
127127
},
128128
}
129129

@@ -219,7 +219,7 @@ func New(cliargs []string) ContextExecutor {
219219
}
220220

221221
// Run runs the application.
222-
func Run(ctx context.Context, args *Args, connections map[string]interface{}) error {
222+
func Run(ctx context.Context, args *Args, connections map[string]interface{}, initstr string) error {
223223
// get user
224224
u, err := user.Current()
225225
if err != nil {
@@ -331,10 +331,16 @@ func Run(ctx context.Context, args *Args, connections map[string]interface{}) er
331331
return err
332332
}
333333
}
334-
// rc file
335-
if rc := env.RCFile(u); !args.NoRC && rc != "" {
336-
if err = h.Include(rc, false); err != nil && err != text.ErrNoSuchFileOrDirectory {
337-
return err
334+
// scripts
335+
if !args.NoRC {
336+
// rc file
337+
if rc := env.RCFile(u); rc != "" {
338+
if err = h.Include(rc, false); err != nil && err != text.ErrNoSuchFileOrDirectory {
339+
return err
340+
}
341+
}
342+
if s := strings.TrimSpace(initstr); s != "" {
343+
h.Reset([]rune(s + "\n"))
338344
}
339345
}
340346
// setup runner

0 commit comments

Comments
 (0)