Class: SDLS::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/sdls/cli.rb

Constant Summary collapse

DEFAULT_CONFIG_PATH =
File.expand_path("~/.config/sdls.yml")

Class Method Summary collapse

Instance Method Summary collapse

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

Returns:

  • (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

#configObject



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. || "[NOT SET]"}"
  puts "  directories: #{current_config.directories.join(", ")}" if current_config.directories&.any?
end

#connectObject



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

#versionObject



42
43
44
# File 'lib/sdls/cli.rb', line 42

def version
  puts SDLS::VERSION
end