safari_bookmarks_parser 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/safari_bookmarks_parser/commands/dump_command.rb +24 -6
- data/lib/safari_bookmarks_parser/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 707f428c27b200d30b70df6ec9a5f33b681b91144460ae9c973041e3d5fb1af2
|
4
|
+
data.tar.gz: eb151045988fc6226db28cb3ffc562a3a18b4f1a28c52eb0526ecb0ffc978d87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bcaebcb7129e64301411f88e6a2275f50c64be6d998406531246c34bf81a436b4ef3b524c5c1edca13a43dfac8c4579a12e68feffe94cd5b01068ba20eaa7086
|
7
|
+
data.tar.gz: 6db98a62641040b2ff3f0da81bd25f19eddf288650ebf9e5ccb1b729c36c211b9c4901b7cfc5dd32a709710bb8c2e28538a34202d3f55b1050fa4621f6330a69
|
data/README.md
CHANGED
@@ -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
|
-
|
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
|
58
|
+
def format_result(result)
|
54
59
|
case @output_format
|
55
60
|
when :json
|
56
|
-
|
61
|
+
JSON.pretty_generate(result)
|
57
62
|
when :yaml
|
58
|
-
|
63
|
+
YAML.dump(result)
|
59
64
|
end
|
60
65
|
end
|
61
66
|
|
62
|
-
|
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|
|