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

Command logic API #7

Open
acatton opened this issue Jul 15, 2015 · 7 comments
Open

Command logic API #7

acatton opened this issue Jul 15, 2015 · 7 comments
Assignees
Milestone

Comments

@acatton
Copy link
Owner

acatton commented Jul 15, 2015

I would like an API like this:

from spm import run

run('echo', 'header').and_(
run('cat', 'file')).and_(
run('echo', 'footer'))
# This should be equivalent to:
#  $ echo header && cat file && echo footer
@acatton acatton added this to the 1.0 milestone Jul 15, 2015
@rockymeza
Copy link

I'm going to make two silly suggestions:

  1. bitwise
run('echo', 'header') & run('cat', 'file')

# also
from operator import and_
and_(run('echo', 'header'), run('cat', 'file'))
  1. return a Truthy
run('echo', 'header') and run('echo', 'header')

@acatton
Copy link
Owner Author

acatton commented Jul 16, 2015

@rockymeza thank you for your suggestion. This issue has been brought up in another thread, and here's my answer.

@acatton
Copy link
Owner Author

acatton commented Jul 16, 2015

Oh and BTW, and can't be overridden in Python.

@rockymeza
Copy link

and doesn't have to be overwritten, and just evaluates if a value is Truthy.

class ReturnValue(object):
    def __init__(self, code, output):
        self.code = code
        # ...

    def __bool__(self):
        return self.code == 0

@rockymeza
Copy link

let me redo my example code since I read the source:

class Subprocess(object):
    # ...
    def __bool__(self):
        self.wait()
        return self.returncode == 0

@gavinwahl
Copy link

The point of and isn't for short-circuit evaluation, but to compose a new
'command' object that outputs the concatenation of two commands' outputs,
to use in a pipeline.

On Wed, Jul 15, 2015 at 11:09 PM, Rocky Meza [email protected]
wrote:

let me redo my example code since I read the source:

class Subprocess(object):
# ...
def bool(self):
self.wait()
return self.returncode == 0


Reply to this email directly or view it on GitHub
#7 (comment).

@rockymeza
Copy link

oh ok, that's fair

-rocky

On Fri, Jul 17, 2015 at 12:19 AM, Gavin Wahl [email protected]
wrote:

The point of and isn't for short-circuit evaluation, but to compose a new
'command' object that outputs the concatenation of two commands' outputs,
to use in a pipeline.

On Wed, Jul 15, 2015 at 11:09 PM, Rocky Meza [email protected]
wrote:

let me redo my example code since I read the source:

class Subprocess(object):

...

def bool(self):
self.wait()
return self.returncode == 0


Reply to this email directly or view it on GitHub
#7 (comment).


Reply to this email directly or view it on GitHub
#7 (comment).

@acatton acatton self-assigned this Jul 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants