Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: properly read stdin in convert prerun (unreleased bug) #28

Merged
merged 1 commit into from
Dec 13, 2023
Merged
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
22 changes: 13 additions & 9 deletions cmd/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func init() {
var convertCmd = newConvertCmd()

func newConvertCmd() *cobra.Command {
var cfgData []byte
res := &cobra.Command{
Use: "convert [flags] <path/to/config_file>",
Short: "Convert between yaml and Aerospike config format.",
Expand Down Expand Up @@ -91,11 +92,6 @@ func newConvertCmd() *cobra.Command {

logger.Debugf("Processing flag format value=%v", srcFormat)

fdata, err := os.ReadFile(srcPath)
if err != nil {
return err
}

var outFmt asconf.Format
switch srcFormat {
case asconf.AsConfig:
Expand All @@ -109,14 +105,14 @@ func newConvertCmd() *cobra.Command {
// if the version option is empty,
// try populating from the metadata
if version == "" {
version, err = getMetaDataItem(fdata, metaKeyAerospikeVersion)
version, err = getMetaDataItem(cfgData, metaKeyAerospikeVersion)
if err != nil && !force {
return errors.Join(errMissingAerospikeVersion, err)
}
}

conf, err := asconf.NewAsconf(
fdata,
cfgData,
srcFormat,
outFmt,
version,
Expand All @@ -142,7 +138,7 @@ func newConvertCmd() *cobra.Command {

// prepend metadata to the config output
mtext, err := genMetaDataText(metaDataArgs{
src: fdata,
src: cfgData,
aerospikeVersion: version,
asconfigVersion: VERSION,
})
Expand Down Expand Up @@ -215,7 +211,15 @@ func newConvertCmd() *cobra.Command {
return err
}

cfgData, err := os.ReadFile(args[0])
// read stdin by default
var srcPath string
if len(args) == 0 {
srcPath = os.Stdin.Name()
} else {
srcPath = args[0]
}

cfgData, err = os.ReadFile(srcPath)
if err != nil {
return err
}
Expand Down