stateful / runme

DevOps Workflows Built with Markdown
https://runme.dev
Apache License 2.0
901 stars 30 forks source link

Refactor internal/command by removing normalizers #576

Closed adambabik closed 1 month ago

adambabik commented 1 month ago

Remove the concept of normalizers from internal/command. Introduce hierarchical commands and command.Factory, instead.

This PR makes it more explicit how various command types are created.

Before there were really two types of commands, namely native and virtual. The latter was using pty under the hood. Whether a particular program was executed inline or through a script file was decided in normalizers that modified command.ProgramConfig (known command.Config earlier).

With this change, each command type is a separate struct. The commands are hierarchical, i.e. there is a command.base and higher-level commands which embed command.internalCommand.

All commands creation is managed by command.Factory so a caller does not need to worry about which command type to create. The caller will typically write the code like this:

factory := NewFactory(cfg, kernel, logger)
cmd := factory.Build(
    &ProgramConfig{
        ProgramName: "echo",
        Arguments:   []string{"-n", "test"},
        Mode:        runnerv2alpha1.CommandMode_COMMAND_MODE_INLINE,
    }
    Options{
        Session:     session,
        Stdout:       stdout
    },
)
sourishkrout commented 1 month ago

One issue I'm noticing is that disableEcho is enabled for the notebook-integrated terminal in the extension which makes any input invisible.

Relevant comment: https://github.com/stateful/runme/issues/566#issuecomment-2118354869

adambabik commented 1 month ago

One issue I'm noticing is that disableEcho is enabled for the notebook-integrated terminal in the extension which makes any input invisible.

Relevant comment: #566 (comment)

This should be addressed in https://github.com/stateful/runme/pull/576/commits/d1d7e2f976bdd4be8f8b281f09e1ce54ce1d1ed6.

sonarcloud[bot] commented 1 month ago

Quality Gate Passed Quality Gate passed

Issues
11 New issues
0 Accepted issues

Measures
0 Security Hotspots
81.2% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud