-
Notifications
You must be signed in to change notification settings - Fork 129
Conditional subobjects based on package version #2911
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
Changes from 1 commit
95d84fa
092a91c
6401c45
4a0836c
b2d9ecc
4bcc828
e4891f6
3e68e2e
a9a124f
4621f9a
21a3eb4
2682da9
b9ec1f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ import ( | |
| "slices" | ||
|
|
||
| "github.com/AlecAivazis/survey/v2" | ||
| "github.com/Masterminds/semver/v3" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
|
|
@@ -19,6 +20,8 @@ import ( | |
| "github.com/elastic/elastic-package/internal/surveyext" | ||
| ) | ||
|
|
||
| var semver3_2_0 = semver.MustParse("3.2.0") | ||
|
|
||
| const createDataStreamLongDescription = `Use this command to create a new data stream. | ||
|
|
||
| The command can extend the package with a new data stream using embedded data stream template and wizard.` | ||
|
|
@@ -80,14 +83,21 @@ func createDataStreamCommandAction(cmd *cobra.Command, args []string) error { | |
| }, | ||
| Validate: survey.Required, | ||
| }, | ||
| { | ||
| } | ||
|
|
||
| sv, err := semver.NewVersion(manifest.SpecVersion) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to obtain spec version from package manifest in \"%s\"", packageRoot) | ||
| } | ||
| if !sv.LessThan(semver3_2_0) { | ||
| qs = append(qs, &survey.Question{ | ||
| Name: "subobjects", | ||
| Prompt: &survey.Confirm{ | ||
| Message: "Enable creation of subobjects for fields with dots in their names?", | ||
| Default: false, | ||
| }, | ||
| Validate: survey.Required, | ||
| }, | ||
| }) | ||
| } | ||
| var answers newDataStreamAnswers | ||
| err = survey.Ask(qs, &answers) | ||
|
|
@@ -173,7 +183,7 @@ func createDataStreamCommandAction(cmd *cobra.Command, args []string) error { | |
| } | ||
| } | ||
|
|
||
| descriptor := createDataStreamDescriptorFromAnswers(answers, packageRoot) | ||
| descriptor := createDataStreamDescriptorFromAnswers(answers, packageRoot, sv) | ||
| err = archetype.CreateDataStream(descriptor) | ||
| if err != nil { | ||
| return fmt.Errorf("can't create new data stream: %w", err) | ||
|
|
@@ -183,14 +193,14 @@ func createDataStreamCommandAction(cmd *cobra.Command, args []string) error { | |
| return nil | ||
| } | ||
|
|
||
| func createDataStreamDescriptorFromAnswers(answers newDataStreamAnswers, packageRoot string) archetype.DataStreamDescriptor { | ||
| func createDataStreamDescriptorFromAnswers(answers newDataStreamAnswers, packageRoot string, specVersion *semver.Version) archetype.DataStreamDescriptor { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps we could unit test this function, checking the manifest it generates for given answers. Further testing could be added to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added some unit testing as suggested, also for the survey questions i've encapsulated this logic to at least check that the question is added or not based on the version. |
||
| manifest := packages.DataStreamManifest{ | ||
| Name: answers.Name, | ||
| Title: answers.Title, | ||
| Type: answers.Type, | ||
| } | ||
|
|
||
| if !answers.Subobjects { | ||
| if !specVersion.LessThan(semver3_2_0) && !answers.Subobjects { | ||
| manifest.Elasticsearch = &packages.Elasticsearch{ | ||
| IndexTemplate: &packages.ManifestIndexTemplate{ | ||
| Mappings: &packages.ManifestMappings{ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.