Skip to content

Commit 7183bdb

Browse files
committed
fix: num args
1 parent 2bee023 commit 7183bdb

1 file changed

Lines changed: 27 additions & 9 deletions

File tree

cmd/substreams-sink-sql/from_proto_export.go

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import (
4141
)
4242

4343
var fromProtoExportCmd = Command(fromProtoExportE,
44-
"from-proto-export <dsn> <manifest> [start]:[stop]",
44+
"from-proto-export <dsn> <manifest> [module] [start]:[stop]",
4545
"Export SQL schema and CSV data exactly as from-proto expects",
4646
Description(`
4747
Generates SQL schema definitions and CSV data dumps that are 100% compatible with from-proto mode.
@@ -51,7 +51,7 @@ var fromProtoExportCmd = Command(fromProtoExportE,
5151
5252
This mode ensures perfect compatibility for operators who need to manage the injection process.
5353
`),
54-
RangeArgs(2, 3),
54+
RangeArgs(2, 4),
5555
Flags(func(flags *pflag.FlagSet) {
5656
// Reuse from-proto flags for consistency
5757
sink.AddFlagsToSet(flags, ignoreUndoBufferSize{})
@@ -80,8 +80,22 @@ func fromProtoExportE(cmd *cobra.Command, args []string) error {
8080

8181
outputModuleName := sink.InferOutputModuleFromPackage
8282
blockRange := ""
83+
84+
// Handle optional module name and block range
8385
if len(args) == 3 {
84-
blockRange = args[2]
86+
// Could be either module name or block range
87+
arg := args[2]
88+
if strings.Contains(arg, ":") {
89+
// It's a block range
90+
blockRange = arg
91+
} else {
92+
// It's a module name
93+
outputModuleName = arg
94+
}
95+
} else if len(args) == 4 {
96+
// Both module name and block range provided
97+
outputModuleName = args[2]
98+
blockRange = args[3]
8599
}
86100

87101
// Parse flags
@@ -119,12 +133,16 @@ func fromProtoExportE(cmd *cobra.Command, args []string) error {
119133
// Parse block range exactly like from-proto
120134
startBlock := sflags.MustGetString(cmd, "start-block")
121135
endBlock := sflags.MustGetString(cmd, "stop-block")
122-
if startBlock != "" {
123-
blockRange = startBlock
124-
}
125-
blockRange += ":"
126-
if endBlock != "0" {
127-
blockRange += endBlock
136+
137+
// Only build blockRange from flags if it wasn't provided as argument
138+
if blockRange == "" {
139+
if startBlock != "" {
140+
blockRange = startBlock
141+
}
142+
blockRange += ":"
143+
if endBlock != "0" {
144+
blockRange += endBlock
145+
}
128146
}
129147

130148
// Parse DSN

0 commit comments

Comments
 (0)