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

Extract ExternalCommand class #72

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

chrismytton
Copy link
Contributor

@chrismytton chrismytton commented Feb 10, 2017

This adds a new ExternalCommand class which encapsulates calling an external command and checking its exit status. This means that the code for running external commands is now nicely tested and easier to reason about.

Fixes #45
Part of #62

Notes to merger

Please complete the following before merging:

@chrismytton chrismytton requested a review from tmtmtmtm February 10, 2017 13:53
@tmtmtmtm tmtmtmtm changed the base branch from 69-shallow-clone to master February 10, 2017 14:22
This outlines the expected usage for the ExternalCommand class.
This class encapsulates running an external command and gathering up the
output.
@chrismytton chrismytton force-pushed the 45-extract-external-commands-class branch from a929fa6 to 7dbcf6a Compare February 10, 2017 15:49
@tmtmtmtm tmtmtmtm force-pushed the master branch 2 times, most recently from a62b715 to 2976cbf Compare May 15, 2017 15:11
Copy link
Contributor

@tmtmtmtm tmtmtmtm left a comment

Choose a reason for hiding this comment

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

This is very old now, and I can't remember any of the context for why it got left hanging. There have been other substantial changes to the code in the meantime, which means this would need to be rebased over master if we continue with it, but the underlying principle seems good, so it's probably worth picking up again.

@env = env
end

def run
Copy link
Contributor

Choose a reason for hiding this comment

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

I got tripped up by this being named as if it were a pure command method (i.e. would have no return value). I think it would be better to name this result or equivalent to highlight that you're actually getting something back from it.


class ExternalCommand
class Result
attr_reader :output
Copy link
Contributor

Choose a reason for hiding this comment

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

it's a bit of a red flag for one of the constructor parameters to be public, and for there to be no behaviour whatsoever in this class related to it.

As the only method is really only a very simple delegation to the other constructor, I wonder if this really needs to be a full class at all, or whether a Struct might be enough for now. Or, perhaps this is a sign that this class should really be taking care of things like cleaning up the output, rather than returning it as-is for the caller to clean up?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants