Skip to content

Commit

Permalink
fix: list command output and update dependencies (#29)
Browse files Browse the repository at this point in the history
* chore: update dependencies

* small refactor

* fix: list command output
  • Loading branch information
FilippoTrotter authored Dec 20, 2024
1 parent b02cbb3 commit 0978e98
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
14 changes: 8 additions & 6 deletions cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (
var contracts embed.FS
var daemon bool

var extension = ".slang"

// runCmd is the base command when called without any subcommands.
func Execute(embeddedFiles embed.FS) {
contracts = embeddedFiles
Expand Down Expand Up @@ -52,7 +50,9 @@ var listCmd = &cobra.Command{
// If no folder argument is provided, list embedded files
fmt.Println("Listing embedded slangroom files:")
err := fouter.CreateFileRouter("", &contracts, "contracts", func(file fouter.SlangFile) {
fmt.Printf("Found file: %s (Path: %s)\n", strings.TrimSuffix(file.FileName, extension), file.Path)
relativePath := strings.TrimPrefix(filepath.Join(file.Dir, file.FileName), "contracts/")
relativePath = strings.TrimSuffix(relativePath, filepath.Ext(relativePath))
fmt.Printf("Found file: %s\n", relativePath)
})
if err != nil {
log.Println("Error:", err)
Expand All @@ -62,7 +62,9 @@ var listCmd = &cobra.Command{
folder := args[0]
fmt.Printf("Listing contracts in folder: %s\n", folder)
err := fouter.CreateFileRouter(folder, nil, "", func(file fouter.SlangFile) {
fmt.Printf("Found file: %s (Path: %s)\n", strings.TrimSuffix(file.FileName, extension), file.Path)
relativeFilePath := filepath.Join(file.Dir, file.FileName)
relativeFilePath = strings.TrimSuffix(relativeFilePath, filepath.Ext(relativeFilePath))
fmt.Printf("Found file: %s\n", relativeFilePath)
})
if err != nil {
log.Println("Error:", err)
Expand Down Expand Up @@ -226,7 +228,7 @@ var runCmd = &cobra.Command{
err := fouter.CreateFileRouter(folder, nil, "", func(file fouter.SlangFile) {
relativeFilePath := filepath.Join(file.Dir, file.FileName)
relativeFilePath = strings.TrimSuffix(relativeFilePath, filepath.Ext(relativeFilePath))
filename := strings.TrimSuffix(file.FileName, extension)
filename := strings.TrimSuffix(file.FileName, filepath.Ext(file.FileName))

if relativeFilePath == filePath {
found = true
Expand Down Expand Up @@ -274,7 +276,7 @@ var runCmd = &cobra.Command{
}

func runFileCommand(file fouter.SlangFile, args []string, metadata *utils.CommandMetadata, argContents map[string]interface{}, isMetadata bool, input *slangroom.SlangroomInput) {
filename := strings.TrimSuffix(file.FileName, extension)
filename := strings.TrimSuffix(file.FileName, filepath.Ext(file.FileName))
err := utils.LoadAdditionalData(file.Dir, filename, input)
if err != nil {
log.Printf("Failed to load data from JSON file: %v\n", err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ func TestListCommand(t *testing.T) {
if !contains(output, "Listing embedded slangroom files:") {
t.Errorf("Expected output to contain 'Listing embedded slangroom files:', got %v", output)
}
if !contains(output, "Found file: hello") {
if !contains(output, "Found file: test/hello") {
t.Errorf("Expected output to contain 'Found file: hello', got %v", output)
}
if !contains(output, "Found file: test") {
if !contains(output, "Found file: test/test") {
t.Errorf("Expected output to contain 'Found file: test', got %v", output)
}
})
Expand Down
18 changes: 9 additions & 9 deletions examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ func Example_listCmd() {

// Output:
// Listing contracts in folder: contracts
// Found file: broken (Path: contracts/test/broken.slang)
// Found file: env (Path: contracts/test/env.slang)
// Found file: execute_zencode (Path: contracts/test/execute_zencode.slang)
// Found file: hello (Path: contracts/test/hello.slang)
// Found file: introspection (Path: contracts/test/introspection.slang)
// Found file: param (Path: contracts/test/param.slang)
// Found file: stdin (Path: contracts/test/stdin.slang)
// Found file: test (Path: contracts/test/test.slang)
// Found file: withschema (Path: contracts/test/withschema.slang)
// Found file: test/broken
// Found file: test/env
// Found file: test/execute_zencode
// Found file: test/hello
// Found file: test/introspection
// Found file: test/param
// Found file: test/stdin
// Found file: test/test
// Found file: test/withschema
}

// Example of using the run command to execute a specific slangroom file.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.23
require (
github.com/ForkbombEu/fouter v0.0.0-20241025081836-854f54912b1c
github.com/davidebianchi/gswagger v0.10.0
github.com/dyne/slangroom-exec/bindings/go v0.0.0-20241217152329-ff77cc681922
github.com/dyne/slangroom-exec/bindings/go v0.0.0-20241219141704-b961cab9047b
github.com/getkin/kin-openapi v0.128.0
github.com/gorilla/mux v1.8.1
github.com/invopop/jsonschema v0.12.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ github.com/dyne/slangroom-exec/bindings/go v0.0.0-20241129112151-e8864edd2fb4 h1
github.com/dyne/slangroom-exec/bindings/go v0.0.0-20241129112151-e8864edd2fb4/go.mod h1:OXlCZWI8XQ8suaNik1N6xmjoH0P6fJ9MH9AK1hxw/sw=
github.com/dyne/slangroom-exec/bindings/go v0.0.0-20241217152329-ff77cc681922 h1:darm4cfsmYK0TPxuSNItzZLmB/+JQ+VUZ535H+nJ/Bc=
github.com/dyne/slangroom-exec/bindings/go v0.0.0-20241217152329-ff77cc681922/go.mod h1:OXlCZWI8XQ8suaNik1N6xmjoH0P6fJ9MH9AK1hxw/sw=
github.com/dyne/slangroom-exec/bindings/go v0.0.0-20241219141704-b961cab9047b h1:1hvlJ8lPeEgBtUJJ+1bZ5jpkcJD1qv/JCNkPi78J/e0=
github.com/dyne/slangroom-exec/bindings/go v0.0.0-20241219141704-b961cab9047b/go.mod h1:OXlCZWI8XQ8suaNik1N6xmjoH0P6fJ9MH9AK1hxw/sw=
github.com/getkin/kin-openapi v0.128.0 h1:jqq3D9vC9pPq1dGcOCv7yOp1DaEe7c/T1vzcLbITSp4=
github.com/getkin/kin-openapi v0.128.0/go.mod h1:OZrfXzUfGrNbsKj+xmFBx6E5c6yH3At/tAKSc2UszXM=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
Expand Down

0 comments on commit 0978e98

Please sign in to comment.