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

Refactor internal/command by removing normalizers #576

Merged
merged 3 commits into from
May 21, 2024

Conversation

adambabik
Copy link
Collaborator

@adambabik adambabik commented May 14, 2024

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
	},
)

@adambabik adambabik force-pushed the adamb/remove-command-normalizers branch 2 times, most recently from 5dc20e0 to 470a3f3 Compare May 16, 2024 18:57
@adambabik adambabik force-pushed the adamb/remove-command-normalizers branch from 96d9c0c to fba647d Compare May 18, 2024 07:01
@adambabik adambabik marked this pull request as ready for review May 18, 2024 21:17
Copy link
Member

@sourishkrout sourishkrout left a comment

Choose a reason for hiding this comment

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

👍 LGTM, just one typo in comments.

return res, args, nil
}

func (c *base) findProgramInKnownInterpretters(programName string, args []string) (string, []string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

findProgramInKnownInterpretters single t in interpreters

@sourishkrout
Copy link
Member

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)

@adambabik
Copy link
Collaborator Author

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 d1d7e2f.

@adambabik adambabik force-pushed the adamb/remove-command-normalizers branch from a171dce to 5882f7c Compare May 21, 2024 20:19
Copy link

sonarcloud bot commented May 21, 2024

@adambabik adambabik merged commit 63a836a into main May 21, 2024
6 checks passed
@adambabik adambabik deleted the adamb/remove-command-normalizers branch May 21, 2024 20:29
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.

2 participants