Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions cmd/cantool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
func main() {
app := kingpin.New("cantool", "CAN tool for Go programmers")
generateCommand(app)
generateSingleCommand(app)
lintCommand(app)
kingpin.MustParse(app.Parse(os.Args[1:]))
}
Expand Down Expand Up @@ -71,6 +72,29 @@ func generateCommand(app *kingpin.Application) {
})
}

func generateSingleCommand(app *kingpin.Application) {
command := app.Command("generate-single", "generate CAN messages for single DBC file")
inputFile := command.
Arg("input-file", "input file").
Required().
ExistingFile()
outputFile := command.
Arg("output-file", "output file").
Required().
String()
command.Action(func(_ *kingpin.ParseContext) error {
outputPath := filepath.Clean(*outputFile)
inputPath := filepath.Clean(*inputFile)
if filepath.Ext(outputPath) != ".go" {
return errors.New("output file must have .go extension")
}
if filepath.Ext(inputPath) != ".dbc" {
return errors.New("input file must have .dbc extension")
}
return genGo(inputPath, outputPath)
})
}

func lintCommand(app *kingpin.Application) {
command := app.Command("lint", "lint DBC files")
fileOrDir := command.
Expand Down