-
-
Save anonymous/5a7a23ee477a16ca31144caf8d023dda to your computer and use it in GitHub Desktop.
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
ATTRS = [:credentials_path, :bucket_name, :s3] | |
attr_reader(*ATTRS) | |
def initialize(credentials_path:, bucket_name:) | |
@credentials_path = credentials_path | |
@bucket_name = bucket_name | |
@prompt = TTY::Prompt.new | |
@s3 = S3.new(bucket_name: bucket_name) | |
parse_args | |
end | |
def parse_args | |
arg = ARGV[0].downcase | |
case arg | |
when '-i', '--interactive' | |
menu | |
when '-h', '--help' | |
# show help doc | |
else | |
delegate!(arg) | |
end | |
end | |
def menu | |
@prompt.select('Select an option') do |p| | |
p.choice '[Push] an object, creating a new version' | |
# ... etc | |
end | |
end | |
####### | |
private | |
####### | |
def delegate!(arg) | |
available_methods = (self.public_methods(false) - ATTRS) | |
if available_methods.include?(arg.to_sym) | |
send(arg) | |
else | |
raise ArgumentError, "No matching method for #{arg}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment