safari_bookmarks_parser 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b79cf6a3fb83906b78ab06394d50c9cf2d15abed628a4951cc32a0d209aaed2
4
- data.tar.gz: 590db97d372270a5880a857885fa8ac6a836b63e61c55a83844cd9f3a0de35c0
3
+ metadata.gz: 707f428c27b200d30b70df6ec9a5f33b681b91144460ae9c973041e3d5fb1af2
4
+ data.tar.gz: eb151045988fc6226db28cb3ffc562a3a18b4f1a28c52eb0526ecb0ffc978d87
5
5
  SHA512:
6
- metadata.gz: 75e07a0d4a48b2569b6164284f5f626bb6dba173a98678b6fe1a0875484eaa400a9673d76330ba9f34850507127474c3adaa8c01dd7b43fc4eb9e1bf518afc64
7
- data.tar.gz: 44eece1dad295720cd00f30319fa9e37e837e7a66cd69bd7975d4900de542c84eaa384b31ddffea13d99034e1b4b6673feedeb3157e288395d323541ccc5a18c
6
+ metadata.gz: bcaebcb7129e64301411f88e6a2275f50c64be6d998406531246c34bf81a436b4ef3b524c5c1edca13a43dfac8c4579a12e68feffe94cd5b01068ba20eaa7086
7
+ data.tar.gz: 6db98a62641040b2ff3f0da81bd25f19eddf288650ebf9e5ccb1b729c36c211b9c4901b7cfc5dd32a709710bb8c2e28538a34202d3f55b1050fa4621f6330a69
data/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  This gem provides a command to dump `~/Library/Safari/Bookmarks.plist` as JSON/YAML.
4
4
 
5
+ ## Prerequisites
6
+
7
+ In "System Preferences" -> "Security & Privacy" -> "Privacy" -> "Full Disk Access", check "Terminal".
8
+
5
9
  ## Installation
6
10
 
7
11
  ```
@@ -7,10 +7,11 @@ require 'yaml'
7
7
  module SafariBookmarksParser
8
8
  module Commands
9
9
  class DumpCommand
10
- attr_reader :plist_path, :output_format, :output_style, :output_parts
10
+ attr_reader :plist_path, :output_path, :output_format, :output_style, :output_parts
11
11
 
12
12
  def initialize(argv)
13
13
  @plist_path = File.expand_path('~/Library/Safari/Bookmarks.plist')
14
+ @output_path = nil
14
15
  @output_format = :json
15
16
  @output_style = :tree
16
17
  @output_parts = :all
@@ -27,9 +28,13 @@ module SafariBookmarksParser
27
28
  result = result_for_output_parts(plist_parser)
28
29
  result = result_for_output_style(result)
29
30
 
30
- output_result(result)
31
+ text = format_result(result)
32
+
33
+ output_text(text)
31
34
  end
32
35
 
36
+ private
37
+
33
38
  def result_for_output_parts(plist_parser)
34
39
  case @output_parts
35
40
  when :all
@@ -50,22 +55,29 @@ module SafariBookmarksParser
50
55
  end
51
56
  end
52
57
 
53
- def output_result(result)
58
+ def format_result(result)
54
59
  case @output_format
55
60
  when :json
56
- puts JSON.pretty_generate(result)
61
+ JSON.pretty_generate(result)
57
62
  when :yaml
58
- puts YAML.dump(result)
63
+ YAML.dump(result)
59
64
  end
60
65
  end
61
66
 
62
- private
67
+ def output_text(text)
68
+ if @output_path
69
+ File.write(@output_path, text)
70
+ else
71
+ puts text
72
+ end
73
+ end
63
74
 
64
75
  def parse_options(argv)
65
76
  parser = OptionParser.new
66
77
 
67
78
  parser.banner = "Usage: #{parser.program_name} dump [options] [~/Library/Safari/Bookmarks.plist]"
68
79
 
80
+ on_output_path(parser)
69
81
  on_output_format(parser)
70
82
 
71
83
  on_tree(parser)
@@ -77,6 +89,12 @@ module SafariBookmarksParser
77
89
  do_parse(parser, argv)
78
90
  end
79
91
 
92
+ def on_output_path(parser)
93
+ parser.on('-o', '--output-path=PATH', 'Output path (default: output to $stdout)') do |value|
94
+ @output_path = value
95
+ end
96
+ end
97
+
80
98
  def on_output_format(parser)
81
99
  desc = "Output format (default: #{@output_format}; one of json or yaml)"
82
100
  parser.on('-f', '--output-format=FORMAT', %w[json yaml], desc) do |value|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SafariBookmarksParser
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: safari_bookmarks_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - healthypackrat