Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --archive option to the open command #10

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/pod/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ def episodes(podcast_id)

desc "open EPISODE_ID", "Open a episode in the browser"
method_option :browser, type: :string, default: "firefox", desc: "Choose the browser."
# TODO
# method_option :archive, type: :boolean, default: false, desc: "Archive the episode."
method_option :archive, type: :boolean, default: false, desc: "Archive the episode."
def open(episode_id)
result = Pod::Commands::Open.call(episode_id, options)

Expand Down
10 changes: 6 additions & 4 deletions lib/pod/commands/open.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
# frozen_string_literal: true

module Pod
module Commands
class Open < Base
def call(episode_id, options = {})
parsed_options = parse_options(options)
browser = parsed_options["browser"] || "firefox"

db = Pod::Storage::SQL.new(db: pod_db_dir)
episode = db.query(
"select link from episodes where id = #{episode_id}",
Pod::Entities::Episode
)[0]
return build_failure_response(details: :not_found) if episode.nil?

browser = parsed_options["browser"] || "firefox"
cmd = "#{browser} #{episode.link}"
cmd << " && bundle exec pod archive #{episode_id}" if parsed_options["archive"]

build_success_response(
details: :episode_found,
metadata: {cmd: "#{browser} #{episode.link}"}
metadata: {cmd: cmd}
)
end
end
Expand Down
13 changes: 13 additions & 0 deletions spec/pod/commands/open_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,18 @@
)
end
end

context "when the archive option is used", :populate_db do
it "returns a success response using the archive option" do
result = described_class.call(1, {"archive" => true})

expect(result[:status]).to eq(:success)
expect(result[:details]).to eq(:episode_found)
expect(result[:metadata][:cmd]).to eq(
"firefox #{TestHelpers::Data.soft_skills_engineering_episodes[0][:link]}" \
" && bundle exec pod archive 1"
)
end
end
end
end