Class: Lipaste::CLI

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

Instance Method Summary collapse

Instance Method Details

#loginObject



43
44
45
# File 'lib/lipaste/cli.rb', line 43

def 
  Lipaste::Config.create_config
end

#logoutObject



48
49
50
# File 'lib/lipaste/cli.rb', line 48

def logout
  Lipaste::Config.destroy
end

#uploadObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/lipaste/cli.rb', line 15

def upload
  conf = Lipaste::Config.read
  unless conf == nil
    begin
      cookie = Lipaste::Lichess. conf[:username], conf[:password]
    rescue
      STDERR.puts "Error logging in to Lichess"
      exit 1
    end
  end

  if options.pgn == nil
    # Use a file from ~/Downloads by default
    pgn = File.read Lipaste::Files.get_latest_downloaded_pgn
  elsif File.exists? options.pgn
    # Read the file if a path is provided
    pgn = File.read options.pgn
  else
    # Treat any other argument as a PGN string
    STDERR.puts "Invalid PGN file: #{options.pgn}"
    exit 1
  end

  puts Lipaste::Lichess.upload cookie, pgn
end

#versionObject



54
55
56
# File 'lib/lipaste/cli.rb', line 54

def version
  say Lipaste::VERSION
end