Skip to content

Commit

Permalink
better error message when using --clone-version and --output together
Browse files Browse the repository at this point in the history
  • Loading branch information
AriehSchneier committed Nov 19, 2024
1 parent a58b583 commit e1c26d0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cmd/sysl/cmd_protobuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (
"reflect"
"strings"

"github.com/spf13/afero"
"gopkg.in/alecthomas/kingpin.v2"

"github.com/anz-bank/sysl/pkg/cmdutils"
"github.com/anz-bank/sysl/pkg/pbutil"
"github.com/anz-bank/sysl/pkg/sysl"

"gopkg.in/alecthomas/kingpin.v2"
)

type protobufCmd struct {
Expand Down Expand Up @@ -52,6 +53,12 @@ func (p *protobufCmd) Execute(args cmdutils.ExecuteArgs) error {
args.Logger.Warn("Using --split-apps to split input into multiple files will BREAK references")
}

if p.splitappspath != "-" || p.output != "-" {
if _, ok := args.Filesystem.(*afero.ReadOnlyFs); ok {
return fmt.Errorf("can not output to a read only FS (likely used both --clone-version and --output)")
}
}

p.output = strings.TrimSpace(p.output)
p.mode = strings.TrimSpace(p.mode)

Expand Down
21 changes: 21 additions & 0 deletions cmd/sysl/sysl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,27 @@ func TestPbCloneVersion(t *testing.T) {
"../../tests/apps_namespaces.sysl")
}

func TestPbCloneVersionWithOutFile(t *testing.T) {
t.Parallel()

logger, hook := test.NewNullLogger()
rc := main2(
[]string{
"sysl",
"protobuf",
"--mode=json",
"--clone-version=298ef0551d1d2b30863d8cf898d974fbf9d009ad",
"--output", "out.sysl",
"../../tests/apps_namespaces.sysl",
},
afero.NewOsFs(), logger, os.Stdin, io.Discard, main3,
)
assert.NotEqual(t, 0, rc)
assert.Equal(t, logrus.ErrorLevel, hook.LastEntry().Level)
reg := regexp.MustCompile(`can not output to a read only FS`)
assert.True(t, reg.MatchString(hook.LastEntry().Message))
}

// runSyslWithExpectedOutput runs the Sysl command line tool with the specified arguments and adds an --output switch
// with a file directed at a temporary output directory. The content of the file are verified to be identical to the
// file specified in the expectedPathFromRepoRoot parameter (no need for "../../" in its path).
Expand Down

0 comments on commit e1c26d0

Please sign in to comment.