38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/noms/command.rb', line 38
def run
parser = Trollop::Parser.new do
version NOMS::Command::VERSION
banner " Usage:\n noms [noms-options] { bookmark | url } [options] [arguments]\n noms-options:\n USAGE\n opt :identity, \"Identity file\", :short => '-i',\n :type => :string,\n :multi => true\n opt :logout, \"Log out of authentication sessions\", :short => '-L'\n opt :verbose, \"Enable verbose output\", :short => '-v'\n opt :list, \"List bookmarks\", :short => '-l'\n opt :bookmarks, \"Bookmark file location (can be specified multiple times)\",\n :short => '-b',\n :type => :string,\n :multi => true\n opt :home, \"Use directory as NOMS_HOME instead of \#{NOMS::Command.home}\",\n :short => '-H',\n :type => :string\n opt :nocache, \"Don't cache files\",\n :short => '-C'\n opt :nodefault_bookmarks, \"Don't consult default bookmarks files\",\n :short => '-X',\n :long => '--nodefault-bookmarks'\n opt :debug, \"Enable debug output\", :short => '-d'\n opt :'plaintext-identity', \"Save identity credentials in plaintext\", :short => '-P'\n stop_on_unknown\n end\n\n @opt = Trollop::with_standard_exception_handling parser do\n parser.parse(@argv)\n end\n\n NOMS::Command.home = @opt[:home] if @opt[:home]\n\n Trollop::with_standard_exception_handling parser do\n raise Trollop::HelpNeeded if @argv.empty? and ! @opt[:list] and ! @opt[:logout]\n end\n\n @opt[:debug] = true if ENV['NOMS_DEBUG'] and ! ENV['NOMS_DEBUG'].empty?\n\n default_bookmarks =\n [ File.join(NOMS::Command.home, 'bookmarks.json'),\n '/usr/local/etc/noms/bookmarks.json',\n '/etc/noms/bookmarks.json'].select { |f| File.exist? f }\n\n @opt[:bookmarks].concat default_bookmarks unless @opt[:nodefault_bookmarks]\n\n @log.level = Logger::WARN\n @log.level = Logger::INFO if @opt[:verbose]\n @log.level = Logger::DEBUG if @opt[:debug]\n\n @bookmark = @opt[:bookmarks].map do |file|\n begin\n File.open(file, 'r') { |fh| JSON.load fh }\n rescue JSON::ParserError => j\n @log.warn \"Couldn't load bookmarks from invalid JSON file \#{file.inspect}\"\n @log.debug \"JSON error: \#{file.inspect}:\#{j.message}\"\n nil\n rescue StandardError => e\n @log.warn \"Couldn't open \#{file.inspect} (\#{e.class}): \#{e.message}\"\n @log.debug \"Error opening \#{file.inspect}: \#{e.backtrace.join(\"\\n\")}\"\n nil\n end\n end.compact.reverse.inject({}) { |h1, h2| h1.merge h2 }\n\n if @opt[:list]\n puts @bookmark.map { |pair| '%-15s -> %s' % pair }\n return 0\n end\n\n if @opt[:logout]\n File.unlink NOMS::Command::Auth::Identity.vault_keyfile if\n File.exist? NOMS::Command::Auth::Identity.vault_keyfile\n return 0\n end\n\n begin\n origin = @bookmark[@argv[0].split('/').first] || @argv[0]\n app = NOMS::Command::Application.new(origin, @argv, :logger => @log,\n :specified_identities => @opt[:identity],\n :cache => ! @opt[:nocache],\n :plaintext_identity => @opt[:'plaintext-identity'])\n app.fetch! # Retrieve page\n app.render! # Run scripts\n out = app.display\n puts out unless out.empty?\n app.exitcode # Return exitcode\n rescue NOMS::Command::Error => e\n @log.error \"noms error: \#{e.message}\"\n 255\n end\nend\n".gsub(/^\s{16}/,'')
|