@@ -2,10 +2,13 @@ package cli
22
33import (
44 "fmt"
5+ "io"
56 "os"
67 "strings"
78
89 "github.com/acorn-io/cmd"
10+ "github.com/acorn-io/gptscript/pkg/assemble"
11+ "github.com/acorn-io/gptscript/pkg/input"
912 "github.com/acorn-io/gptscript/pkg/loader"
1013 "github.com/acorn-io/gptscript/pkg/runner"
1114 "github.com/acorn-io/gptscript/pkg/version"
@@ -15,8 +18,10 @@ import (
1518
1619type GPTScript struct {
1720 runner.Options
18- Output string `usage:"Save output to a file" short:"o"`
19- SubTool string `usage:"Target tool name in file to run"`
21+ Output string `usage:"Save output to a file" short:"o"`
22+ Input string `usage:"Read input from a file (\"-\" for stdin)" short:"f"`
23+ SubTool string `usage:"Target tool name in file to run"`
24+ Assemble bool `usage:"Assemble tool to a single artifact and saved to --output"`
2025}
2126
2227func New () * cobra.Command {
@@ -26,6 +31,7 @@ func New() *cobra.Command {
2631func (r * GPTScript ) Customize (cmd * cobra.Command ) {
2732 cmd .Use = version .ProgramName
2833 cmd .Args = cobra .MinimumNArgs (1 )
34+ cmd .Flags ().SetInterspersed (false )
2935}
3036
3137func (r * GPTScript ) Run (cmd * cobra.Command , args []string ) error {
@@ -34,6 +40,20 @@ func (r *GPTScript) Run(cmd *cobra.Command, args []string) error {
3440 return err
3541 }
3642
43+ if r .Assemble {
44+ var out io.Writer = os .Stdout
45+ if r .Output != "" {
46+ f , err := os .Create (r .Output )
47+ if err != nil {
48+ return fmt .Errorf ("opening %s: %w" , r .Output , err )
49+ }
50+ defer f .Close ()
51+ out = f
52+ }
53+
54+ return assemble .Assemble (cmd .Context (), * tool , out )
55+ }
56+
3757 if ! r .Quiet {
3858 if ! term .IsTerminal (int (os .Stdout .Fd ())) {
3959 r .Quiet = true
@@ -45,7 +65,16 @@ func (r *GPTScript) Run(cmd *cobra.Command, args []string) error {
4565 return err
4666 }
4767
48- s , err := runner .Run (cmd .Context (), * tool , "" )
68+ toolInput , err := input .FromFile (r .Input )
69+ if err != nil {
70+ return err
71+ }
72+
73+ if toolInput == "" {
74+ toolInput = input .FromArgs (args [1 :])
75+ }
76+
77+ s , err := runner .Run (cmd .Context (), * tool , toolInput )
4978 if err != nil {
5079 return err
5180 }
0 commit comments