Class: SDLS::CLI
- Inherits:
-
Thor
- Object
- Thor
- SDLS::CLI
- Defined in:
- lib/sdls/cli.rb
Constant Summary collapse
- DEFAULT_CONFIG_PATH =
File.("~/.config/sdls.yml")
Class Method Summary collapse
Instance Method Summary collapse
- #add(magnet = nil) ⇒ Object
- #config ⇒ Object
- #connect ⇒ Object
-
#initialize(*args, config_path: nil, **kwargs) ⇒ CLI
constructor
A new instance of CLI.
- #version ⇒ Object
Constructor Details
#initialize(*args, config_path: nil, **kwargs) ⇒ CLI
Returns a new instance of CLI.
11 12 13 14 |
# File 'lib/sdls/cli.rb', line 11 def initialize(*args, config_path: nil, **kwargs) super(*args, **kwargs) @config_path = config_path || ENV["SDLS_CONFIG_PATH"] || DEFAULT_CONFIG_PATH end |
Class Method Details
.exit_on_failure? ⇒ Boolean
87 88 89 |
# File 'lib/sdls/cli.rb', line 87 def self.exit_on_failure? true end |
Instance Method Details
#add(magnet = nil) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/sdls/cli.rb', line 69 def add(magnet = nil) magnet ||= Clipboard.paste.strip unless magnet&.start_with?("magnet:") warn "Invalid or missing magnet link." exit 1 end name = extract_torrent_name(magnet) puts "Adding torrent: #{name}" if name prompt = TTY::Prompt.new destination = prompt.select("Choose download directory", current_config.directories, default: current_config.directories.first) success = client.create_download(magnet: magnet, destination: destination) exit 1 unless success end |
#config ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/sdls/cli.rb', line 47 def config puts "Current config:" puts " host: #{current_config.host}" puts " username: #{current_config.username}" puts " password: [REDACTED]" puts " op_item_name: #{current_config.op_item_name || "[NOT SET]"}" puts " op_account: #{current_config.op_account || "[NOT SET]"}" puts " directories: #{current_config.directories.join(", ")}" if current_config.directories&.any? end |
#connect ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/sdls/cli.rb', line 58 def connect sid = client.authenticate if sid puts "Connection successful. Session ID: #{sid.slice(0, 8)}..." else puts "Connection failed. Please check your credentials or server status." exit 1 end end |