feat: allow fetching bookmark title from remote server - #21
Draft
dhth wants to merge 6 commits into
Draft
Conversation
dstlled-diffexpanddiff --git a/2b1afe40/src/args.rs b/04305297/src/args.rs
index 2dcdec8..b948598 100644
--- a/2b1afe40/src/args.rs
+++ b/04305297/src/args.rs
@@ -97,0 +98,3 @@ pub enum BmmCommand {
+ /// Whether to fetch bookmark title automatically
+ #[arg(short = 'F', long = "fetch")]
+ fetch: bool,
diff --git a/2b1afe40/src/cli/save.rs b/04305297/src/cli/save.rs
index a5c9c93..113386b 100644
--- a/2b1afe40/src/cli/save.rs
+++ b/04305297/src/cli/save.rs
@@ -13,0 +14,4 @@ pub enum SaveBookmarkError {
+ #[error("couldn't fetch details: {0}")]
+ CouldntFetchDetails(#[from] FetchUriDetailsError),
+ #[error("no details fetched from remote server")]
+ NoDetailsFetched,
@@ -40,0 +45,7 @@ pub enum ParsingTempFileContentError {
+pub struct SaveConfig {
+ pub use_editor: bool,
+ pub fail_if_uri_already_saved: bool,
+ pub reset_missing: bool,
+ pub ignore_attribute_errors: bool,
+ pub fetch: bool,
+}
@@ -43,5 +54,4 @@ pub fn save_bookmark(
- potential_bookmark: PotentialBookmark,
- use_editor: bool,
- fail_if_uri_saved: bool,
- reset_missing: bool,
- ignore_attribute_errors: bool,
+ uri: String,
+ title: Option<String>,
+ tags: &[String],
+ save_config: SaveConfig,
@@ -50 +60,3 @@ fn get_bookmark_update_details_from_temp_file(
- bookmark: &SavedBookmark,
+ uri: &str,
+ title: Option<&str>,
+ tags: Option<&str>,
@@ -53,0 +66,2 @@ fn get_new_bookmark_details_from_temp_file(
+ title: Option<&str>,
+ tags: Option<&str>,
@@ -57,2 +71,10 @@ fn get_env_var(key: &str) -> Result<String, CouldntGetDetailsViaEditorError>
-fn get_update_bookmark_tmp_file_contents(bookmark: &SavedBookmark) -> String
-fn get_create_bookmark_tmp_file_contents(uri: &str) -> String
+fn get_update_bookmark_tmp_file_contents(
+ uri: &str,
+ title: Option<&str>,
+ tags: Option<&str>,
+) -> String
+fn get_create_bookmark_tmp_file_contents(
+ uri: &str,
+ title: Option<&str>,
+ tags: Option<&str>,
+) -> String
diff --git a/04305297/src/service/fetch.rs b/04305297/src/service/fetch.rs
new file mode 100644
index 0000000..68113f8
--- /dev/null
+++ b/04305297/src/service/fetch.rs
@@ -0,0 +1,13 @@
+pub enum FetchUriDetailsError {
+ #[error("uri is incorrect: {0}")]
+ IncorrectUri(#[from] ParseError),
+ #[error(transparent)]
+ RequestUri(#[from] ReqwestError),
+}
+pub fn fetch_uri_details(uri: &str) -> Result<Option<String>, FetchUriDetailsError>
+fn get_title_from_html(html: &str) -> Option<String>
+fn parsing_simple_html_works()
+fn parsing_html_with_og_tags_only_works()
+fn parsing_html_with_both_title_and_og_tags_works()
+fn parsing_empty_html_works()
+fn parsing_incorrect_html_works()
diff --git a/2b1afe40/tests/save_test.rs b/04305297/tests/save_test.rs
index 4fa43d0..c390063 100644
--- a/2b1afe40/tests/save_test.rs
+++ b/04305297/tests/save_test.rs
@@ -2,0 +3 @@ fn saving_a_new_bookmark_with_title_and_tags_works()
+fn updating_bookmarks_with_no_new_data_works()
@@ -4 +5,3 @@ fn extending_tags_for_a_saved_bookmark_works()
-fn resetting_properties_on_bookmark_update_works()
+fn resetting_all_data_for_a_bookmark_works()
+fn resetting_title_on_bookmark_update_works()
+fn resetting_tags_on_bookmark_update_works()
@@ -6,0 +10 @@ fn force_saving_a_new_bookmark_with_invalid_tags_works()
+fn fetching_title_from_remote_server_works()
@@ -8,0 +13 @@ fn saving_a_new_bookmark_with_an_invalid_tag_fails()
+fn updating_a_bookmarks_with_no_new_details_fails_if_requested()
@@ -10,0 +16 @@ fn saving_a_new_bookmark_with_incorrect_text_editor_configured_fails()
+fn fetching_details_for_non_existent_uri_should_fail() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a flag to
bmm saveto allow fetching bookmark details from remote server.