Skip to content

Instantly share code, notes, and snippets.

@radium226
Created September 4, 2016 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radium226/ceb4b81c48357d81510b275a813189b4 to your computer and use it in GitHub Desktop.
Save radium226/ceb4b81c48357d81510b275a813189b4 to your computer and use it in GitHub Desktop.
#!/bin/env python
class Option(object):
def __init__(self, key, name, expects_value):
self.key = key
self.name = name
self.expects_value = expects_value
def format_value(self, value):
formatted_value = None
if hasattr(value, "name"):
formatted_value = file.name
else:
formatted_value = str(value)
return formatted_value
class Binary(object):
def __init__(self, path):
self.path = path
self.options = dict()
def option(self, key, name, expects_value = True, value_type = None, hidden = False, default = None):
self.options[key] = Option(key, name, expects_value)
return self
@staticmethod
def __format_option(option, value):
return [option.name, option.format_value(value)]
def __call__(self, *args, **kwargs):
arguments = [self.path]
for key, value in kwargs.items():
option = self.options[key]
arguments += self.__format_option(option, value)
arguments += args
print(arguments)
@classmethod
def path(cls, path):
return Binary(path)
if __name__ == "__main__":
ffmpeg = Binary \
.path("/usr/bin/ffmpeg") \
.option("input", "-i", expects_value = True)
ffmpeg(input = "test")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment