Skip to content

Commit

Permalink
Merge pull request #5 from Fingertips/manfred-1-config
Browse files Browse the repository at this point in the history
Configuration and API changes
  • Loading branch information
Manfred authored May 13, 2024
2 parents 40edf5a + e17a564 commit 12b741d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
14 changes: 12 additions & 2 deletions src/teletube/cli.cr
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ module Teletube
end
when "config"
@config.attributes = {
"endpoint" => context.params["endpoint"].as_s,
"token" => context.params["token"].as_s,
"endpoint" => endoint,
"token" => token,
}
@config.save
when "categories"
Expand Down Expand Up @@ -131,5 +131,15 @@ module Teletube
STDERR.puts("⚠️ #{error}")
end
end

private def endoint
endpoint = context.params["endpoint"]?
endpoint ? endpoint.as_s : ""
end

private def token
token = context.params["token"]?
token ? token.as_s : ""
end
end
end
8 changes: 4 additions & 4 deletions src/teletube/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require "yaml"
module Teletube
class Config
ENDPOINT = "https://tube.switch.ch"
PATH = Path["~/.teletube.yml"].expand(home: true)
PATH = Path["~/.teletube.yml"].expand(home: true)

getter token : String?
getter endpoint : String?
Expand All @@ -16,8 +16,8 @@ module Teletube
end

def attributes=(attributes : YAML::Any)
@token = attributes["token"].as_s if attributes["token"]
@endpoint = attributes["endpoint"].as_s if attributes["endpoint"]
@token = attributes["token"].as_s?
@endpoint = attributes["endpoint"].as_s?
end

def attributes=(attributes : Hash(String, String))
Expand All @@ -31,7 +31,7 @@ module Teletube

def save(path = PATH)
File.open(path, "wb") do |file|
file << YAML.dump({ "token" => @token, "endpoint" => @endpoint })
file << YAML.dump({"token" => @token, "endpoint" => @endpoint})
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/teletube/option_parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module Teletube
parser.on("list", "List all owned channels.") do
context.command = "list"
parser.on("--role ROLE", "The role of the authenticated profile.") do |role|
if %w[owner contributor].includes?(role)
if %w[owner contributor collaborator].includes?(role)
context.params["role"] = JSON::Any.new(role)
else
context.errors << "Please specify either owner or contributor for the role."
Expand Down
2 changes: 1 addition & 1 deletion src/teletube/resources/channel.cr
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module Teletube
parser.on("--no-downloadable", "Opposite of --downloadable") do
context.params["downloadable"] = JSON::Any.new(false)
end
parser.on("--archive-original-video-files", "The uploaded video file will be archived and will continue to be available for download to the channel admins.") do
parser.on("--archive-original-video-files", "Deprecated. The uploaded video file is now always archived.") do
context.params["archive_original_video_files"] = JSON::Any.new(true)
end
parser.on("--no-archive-original-video-files", "Opposite of --archive-original-video-files") do
Expand Down

0 comments on commit 12b741d

Please sign in to comment.