Skip to content

Conversation

@kaorukobo
Copy link

Describe the change

This adds a tag option to TTY::Command.new and the run method. This allows you to prepend any arbitrary string to the beginning of log output.

To clearly show the differences from the existing codebase, the commits are split as follows:

  • One commit showing the essential changes
  • Two commits for test refactoring

Why are we doing this?

Currently, tty-command's log output only allows you to control whether UUIDs are on or off. Meaningless UUID strings make it very difficult to identify the output of multiple interleaved command executions.

$ ruby -rtty-command -e 'cmd=TTY::Command.new; cmd.run("echo rsync from server A"); cmd.run("echo rsync from server B")' 
[9ad3f783] Running echo rsync from server A
[9ad3f783]      rsync from server A
[9ad3f783] Finished in 0.003 seconds with exit status 0 (successful)
[8d98f58b] Running echo rsync from server B
[8d98f58b]      rsync from server B
[8d98f58b] Finished in 0.002 seconds with exit status 0 (successful)

Benefits

By allowing arbitrary strings to be displayed at the beginning of logs, you can easily identify the output of multiple interleaved command executions.

$ ruby -rtty-command -e 'cmd=TTY::Command.new; cmd.run("echo rsync from server A", tag: "serverA"); cmd.run("echo rsync from server B", tag: "serverB")' 
[serverA] Running echo rsync from server A
[serverA]      rsync from server A
[serverA] Finished in 0.003 seconds with exit status 0 (successful)
[serverB] Running echo rsync from server B
[serverB]      rsync from server B
[serverB] Finished in 0.002 seconds with exit status 0 (successful)

Drawbacks

None. All existing code will continue to work as before without any modifications.

Requirements

  • Tests written & passing locally?
  • Code style checked? ==> I ran rubocop but it shows too many errors even in unmodified codebase.
  • Rebased with master branch?
  • Documentation updated?
  • Changelog updated?

@jrochkind
Copy link

Ooh, I like this! Yes please.

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.

3 participants