Created
September 1, 2016 17:12
-
-
Save psyho/e56c4597e05b90e1d4d03a13d0a4dd0b to your computer and use it in GitHub Desktop.
CLI builder example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module HashConstructor | |
def initialize(attrs = {}) | |
attrs.each do |name, value| | |
send("#{name}=", value) | |
end | |
end | |
end | |
class AwsCli | |
include HashConstructor | |
attr_accessor :region | |
def s3(bucket) | |
S3.new(aws: self, bucket: bucket) | |
end | |
def help | |
run('help') | |
end | |
def run(*args) | |
system('aws', '--region', region, *args) | |
end | |
class S3 | |
include HashConstructor | |
attr_accessor :aws, :bucket | |
def ls | |
run('ls', bucket) | |
end | |
def run(*args) | |
aws.run('s3', *args) | |
end | |
end | |
end | |
aws = AwsCli.new(region: 'us-west-2') | |
aws.help | |
aws.s3('zoomer-menus-images-testing').ls |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment