class AudioAddict::Commands::ConfigCmd
Public Instance Methods
check_command()
click to toggle source
# File lib/audio_addict/commands/config.rb, line 79 def check_command errors = verify_and_show_keys required_keys, critical: true warnings = verify_and_show_keys optional_keys say "Done. #{errors} errors, #{warnings} warnings." errors > 0 ? 1 : 0 end
del_command()
click to toggle source
# File lib/audio_addict/commands/config.rb, line 50 def del_command key = args["KEY"].to_sym Config.delete key Config.save say "!txtgrn!Deleted" end
edit_command()
click to toggle source
# File lib/audio_addict/commands/config.rb, line 66 def edit_command editor = ENV["EDITOR"] || "vi" system "#{editor} #{Config.path}" end
get_command()
click to toggle source
# File lib/audio_addict/commands/config.rb, line 36 def get_command key = args["KEY"].to_sym value = Config.properties[key] say value ? "!txtgrn!#{value}" : "!txtred!<Unset>" end
guide_command()
click to toggle source
# File lib/audio_addict/commands/config.rb, line 71 def guide_command key_guide.each do |key, value| say "!txtgrn!#{key}" say word_wrap " #{value}" say "" end end
set_command()
click to toggle source
# File lib/audio_addict/commands/config.rb, line 42 def set_command key = args["KEY"].to_sym value = args["VALUE"] Config.properties[key] = value Config.save say "!txtgrn!#{key}=#{value}" end
show_command()
click to toggle source
# File lib/audio_addict/commands/config.rb, line 57 def show_command say "!undpur!# #{Config.path}" if File.exist? Config.path puts File.read Config.path else say "!txtred!File Not Found" end end
Private Instance Methods
key_guide()
click to toggle source
# File lib/audio_addict/commands/config.rb, line 103 def key_guide { email: "Last email used for logging in.\nUsually set with !txtpur!radio login!txtrst!.", session_key: "Used for authentication.\nUsually set with !txtpur!radio login!txtrst!.", listen_key: "Used for generating playlists.\nUsually set with !txtpur!radio login!txtrst!.", network: "Specify the AudioAddict network you are currently listening to.\nUsually set with !txtpur!radio set!txtrst!.", channel: "Specify the AudioAddict channel you are currently listening to.\nUsually set with !txtpur!radio set!txtrst!.", like_log: "Specify the path to store all your positive votes.\nIf this is not set, votes will only be sent to AudioAddict and not logged locally.", cache_dir: "Specify the path to store API response cache.\nDefault: ~/.audio_addict/cache", cache_life: "Specify the cache life period.\nDefault: 6h.", } end
optional_keys()
click to toggle source
# File lib/audio_addict/commands/config.rb, line 126 def optional_keys { like_log: "config set like_log PATH", } end
required_keys()
click to toggle source
# File lib/audio_addict/commands/config.rb, line 116 def required_keys { email: "login", session_key: "login", listen_key: "login", network: "set", channel: "set", } end
verify_and_show_keys(keys, critical: false)
click to toggle source
# File lib/audio_addict/commands/config.rb, line 89 def verify_and_show_keys(keys, critical: false) problems = 0 prefix = critical ? "!txtred!Error !txtrst!" : "!txtylw!Warning!txtrst!" keys.each do |key, command| if !Config.has_key? key problems += 1 say "#{prefix} : Key !txtgrn!#{key}!txtrst! is not set. Fix with !txtpur!radio #{command}!txtrst!." end end problems end