/bin/bitbucket-backup
Ruby | 71 lines | 61 code | 9 blank | 1 comment | 1 complexity | 8652015cdc5b73f0e7e21068aacd47cc MD5 | raw file
Possible License(s): 0BSD
- #!/usr/bin/env ruby
- require "highline/import"
- require "bitbucket-backup"
- require "optparse"
- require "yaml"
- options = {}
- parser = OptionParser.new do |opts|
- cmd = File.basename($0)
-
- opts.banner = "usage: #{cmd} [options] /path/to/backupdir"
-
- opts.on("-a", "--all-repos", "Backup all visible repos to user.") do
- options["all_repos"] = true
- end
-
- opts.on("-c", "--config FILE", "Path to config file.") do |config_file|
- options["config_file"] = config_file
- end
-
- opts.on("-u", "--username USERNAME", "Username for account to be backed up.") do |username|
- options["username"] = username
- end
-
- opts.on("-h", "--help", "Show this help message and exit.") do
- puts opts
- exit
- end
-
- opts.on("-v", "--version", "Display the program's version and exit.") do
- puts "#{cmd} (version #{Bitbucket::Backup::VERSION})"
- exit
- end
- end
- parser.parse!
- config = {}
- if options["config_file"]
- begin
- path = File.expand_path(options["config_file"])
-
- config = YAML.load_file(path)
- unless config
- puts "Error: invalid config file: #{path}."
- exit
- end
- rescue YAML::SyntaxError, StandardError
- puts "Error: invalid config file: #{path}."
- exit
- end
- end
- config.merge!(options)
- if ARGV.empty? || !config["username"]
- puts parser.banner
- exit
- end
- if !config["password"]
- config["password"] = ask("Password: ") do |q|
- q.echo = false
- end
- end
- Bitbucket::Backup.run(config["username"], config["password"], ARGV.first, config["all_repos"] || false)