Skip to content

Add non-interactive mode to create commands#3341

Open
P1llus wants to merge 2 commits intomainfrom
cli_tui_non_interactive
Open

Add non-interactive mode to create commands#3341
P1llus wants to merge 2 commits intomainfrom
cli_tui_non_interactive

Conversation

@P1llus
Copy link
Member

@P1llus P1llus commented Mar 5, 2026

Add CLI flag support to create package and create data-stream commands

Summary

Adds optional CLI flags to create package and create data-stream, allowing them to run without the TUI wizard — enabling automation, scripts, and LLM agents to create packages and data streams deterministically.

When any flag is explicitly passed, the TUI is skipped automatically.

Only flags required to make template decisions (package type, data stream type, input types) were added. All other fields use sensible production defaults.

Also fixes a minor YAML indentation bug in VarValueYamlString where multi-line block scalars (e.g. syslog_options, ssl defaults) lost their relative indentation when rendered into data stream manifests, causing newly created packages to fail format/lint checks.


Changes

internal/packages/packages.go

Centralizes type definitions and fixes YAML rendering:

  • Exports AllowedPackageTypes, AllowedDataStreamTypes, and AllowedLogsInputTypes so the TUI wizard, CLI validation, and manifest checks all share a single source of truth
  • Fixes VarValueYamlString: multi-line YAML values were losing indentation on continuation lines because only the first line inherited the template's base indentation — now pads continuation lines by numSpaces so relative indentation stays valid
  • isPackageManifest reuses AllowedPackageTypes instead of a local duplicate

cmd/create.go

Declares flag name constants and registers flags on both subcommands:

  • create package: --type, --name
  • create data-stream: --type, --name, --inputs

cmd/create_package.go

Adds createPackageNonInteractive():

  • Triggered automatically when --type or --name is passed (detected via cmd.Flags().Changed())
  • Validates --type against packages.AllowedPackageTypes and --name against existing validators
  • Fills remaining fields with production defaults (version 0.0.1, Elastic License 2.0, basic subscription, etc.)

cmd/create_data_stream.go

Adds createDataStreamNonInteractive():

  • Triggered automatically when --name, --type, or --inputs is passed
  • Requires --name and --type (validated against packages.AllowedDataStreamTypes)
  • For logs, requires --inputs validated against packages.AllowedLogsInputTypes
  • For metrics, auto-enables synthetic source + time series mode
  • TUI wizard uses AllowedLogsInputTypes map for both option keys and description labels

Tests

Covers descriptor construction, type validation, survey questions, and YAML rendering:

  • cmd/create_package_test.go — Package descriptor construction and AllowedPackageTypes validation
  • cmd/create_data_stream_test.go — Data stream descriptor construction, input type validation, and survey question generation per spec version
  • internal/packages/packages_test.goTestVarValueYamlString covering scalars, lists, custom indentation, and a regression test simulating template embedding at indent 6

Usage

# Create a package (skips TUI automatically)
elastic-package create package --type integration --name my_package

# Create a logs data stream with specific inputs
elastic-package create data-stream --name access --type logs --inputs filestream,tcp

# Create a metrics data stream
elastic-package create data-stream --name status --type metrics

# TUI wizard still launches when no flags are passed
elastic-package create package
elastic-package create data-stream

@ilyannn
Copy link

ilyannn commented Mar 5, 2026

Do we really need the --non-interactive flag if all the data are already known?

@mrodm mrodm requested a review from a team March 5, 2026 12:22
@P1llus
Copy link
Member Author

P1llus commented Mar 5, 2026

Do we really need the --non-interactive flag if all the data are already known?

Not really, we could skip the TUI if parameters are provided? Less to input

@elasticmachine
Copy link
Collaborator

💔 Build Failed

Failed CI Steps

History

Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks! Added some suggestions about the help strings.

Args: cobra.NoArgs,
RunE: createPackageCommandAction,
}
createPackageCmd.Flags().String(createPackageTypeFlag, "integration", "package type (input, integration, content); when set the TUI wizard is skipped")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TUI is an implementation detail that we don't need to expose to users.

Suggested change
createPackageCmd.Flags().String(createPackageTypeFlag, "integration", "package type (input, integration, content); when set the TUI wizard is skipped")
createPackageCmd.Flags().String(createPackageTypeFlag, "integration", "set to input, integration or content to create an empty package of the given type in a non-interactive way")

RunE: createPackageCommandAction,
}
createPackageCmd.Flags().String(createPackageTypeFlag, "integration", "package type (input, integration, content); when set the TUI wizard is skipped")
createPackageCmd.Flags().String(createPackageNameFlag, "new_package", "package name; when set the TUI wizard is skipped")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
createPackageCmd.Flags().String(createPackageNameFlag, "new_package", "package name; when set the TUI wizard is skipped")
createPackageCmd.Flags().String(createPackageNameFlag, "new_package", "set to create an empty package with the given name in a non-interactive way")

Comment on lines +45 to +47
createDataStreamCmd.Flags().String(createDataStreamNameFlag, "new_data_stream", "data stream name; when set the TUI wizard is skipped")
createDataStreamCmd.Flags().String(createDataStreamTypeFlag, "logs", "data stream type (logs, metrics); when set the TUI wizard is skipped")
createDataStreamCmd.Flags().StringSlice(createDataStreamInputsFlag, nil, "input types for logs data streams (e.g. filestream,tcp); when set the TUI wizard is skipped")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review these descriptions too to avoid references to TUI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants