Skip to content

Instantly share code, notes, and snippets.

@psyho
Created September 1, 2016 17:12
Show Gist options
  • Save psyho/e56c4597e05b90e1d4d03a13d0a4dd0b to your computer and use it in GitHub Desktop.
Save psyho/e56c4597e05b90e1d4d03a13d0a4dd0b to your computer and use it in GitHub Desktop.
CLI builder example
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