Class: Fling::CLI
- Inherits:
-
Thor
- Object
- Thor
- Fling::CLI
- Defined in:
- lib/fling/cli.rb
Overview
The Fling Command Line Interface
Instance Method Summary collapse
Instance Method Details
#config(file_or_uri) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/fling/cli.rb', line 39 def config(file_or_uri) require "fling/install" if file_or_uri[%r{\Ahttps://}] uri = URI(file_or_uri) ciphertext = Net::HTTP.get(uri) elsif file_or_uri[%r{\Ahttp://}] # ಠ_ಠ say "Friends don't let friends use http://" exit 1 else # Perhaps it's a file? unless File.exist?(file_or_uri) say "No such file: #{file_or_uri}" exit 1 end ciphertext = File.read(file_or_uri) end say "Loaded #{file_or_uri}" password = ask "Please enter the password to decrypt the config:", echo: false say # newline begin config = Config.decrypt(password, ciphertext) rescue Fling::ConfigError => ex say "Error: Couldn't decrypt config: #{ex}" exit 1 end config_dir = File.("~/.tahoe") if File.exist?(config_dir) say "Error: #{config_dir} already exists" exit 1 end config.render(config_dir) say "Created #{config_dir}!" say "Start Tahoe by running 'tahoe start'" end |
#install ⇒ Object
10 11 12 13 14 |
# File 'lib/fling/cli.rb', line 10 def install require "fling/install" Install.run say "Now run 'fling config [file or url]' to configure Tahoe-LAFS" end |
#provision(config_file) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/fling/cli.rb', line 17 def provision(config_file) say "Provisioning #{config_file}" introducer = ask "What is your introducer FURL? (e.g. pb://...)" dropcap = ask "What is your 'dropcap'? (e.g. URI:DIR2:...)" password = ask "Please enter a password to encrypt the config:", echo: false say "\nGenerating encrypted config, please wait..." config = Config.encrypt( password, "introducer" => introducer, "dropcap" => dropcap, "convergence" => Encoding.encode(RbNaCl::Random.random_bytes(32)), "salt" => Encoding.encode(RbNaCl::Random.random_bytes(32)) ) File.open(config_file, "w") { |file| file << config } say "Created #{config_file}" end |