@@ -97,6 +97,24 @@ func main() {
9797 },
9898 },
9999 },
100+ {
101+ Name : "init" ,
102+ Usage : "Generate a commented test scaffold for a source SQL file" ,
103+ ArgsUsage : "<source.sql>" ,
104+ Action : initCommand ,
105+ Flags : []urfavecli.Flag {
106+ & urfavecli.StringFlag {
107+ Name : "output" ,
108+ Aliases : []string {"o" },
109+ Usage : "Output path for the scaffold (default: sibling <stem>_test.sql)" ,
110+ DefaultText : "<source_dir>/<stem>_test.sql" ,
111+ },
112+ & urfavecli.BoolFlag {
113+ Name : "force" ,
114+ Usage : "Overwrite the output file if it already exists" ,
115+ },
116+ },
117+ },
100118 },
101119 }
102120
@@ -163,3 +181,25 @@ func mergeCommand(ctx context.Context, cmd *urfavecli.Command) error {
163181 inputs := cmd .Args ().Slice ()
164182 return cli .Merge (ctx , inputs , output )
165183}
184+
185+ // initCommand handles the 'pgcov init' command.
186+ //
187+ // It generates a commented test scaffold for an existing source SQL file,
188+ // using the lexer-driven extraction in internal/cli to find CREATE
189+ // [OR REPLACE] FUNCTION statements and emit a commented call template for
190+ // each. The default target path is the sibling <stem>_test.sql.
191+ func initCommand (_ context.Context , cmd * urfavecli.Command ) error {
192+ source := cmd .Args ().First ()
193+ if source == "" {
194+ return fmt .Errorf ("usage: pgcov init <source.sql> [--output PATH] [--force]" )
195+ }
196+ output := cmd .String ("output" )
197+ force := cmd .Bool ("force" )
198+
199+ outPath , err := cli .Init (source , output , force )
200+ if err != nil {
201+ return err
202+ }
203+ fmt .Fprintf (os .Stderr , "Scaffold written to %s\n " , outPath )
204+ return nil
205+ }
0 commit comments