squish.lua

changeset 16
aaf1b38007d8
parent 15
2aa02b99d2af
child 19
f72a0f535301
equal deleted inserted replaced
15:2aa02b99d2af 16:aaf1b38007d8
1 #!/usr/bin/env lua 1 #!/usr/bin/env lua
2 2
3 local short_opts = { v = "verbose", vv = "very_verbose", o = "output", q = "quiet", qq = "very_quiet" } 3 local short_opts = { v = "verbose", vv = "very_verbose", o = "output", q = "quiet", qq = "very_quiet" }
4 local opts = {}; 4 local opts = { use_http = false };
5 5
6 for _, opt in ipairs(arg) do 6 for _, opt in ipairs(arg) do
7 if opt:match("^%-") then 7 if opt:match("^%-") then
8 local name = opt:match("^%-%-?([^%s=]+)()") 8 local name = opt:match("^%-%-?([^%s=]+)()")
9 name = (short_opts[name] or name):gsub("%-+", "_"); 9 name = (short_opts[name] or name):gsub("%-+", "_");
100 f:close(); 100 f:close();
101 101
102 return data; 102 return data;
103 end 103 end
104 104
105 function fetch.http(url) 105 if opts.use_http then
106 local http = require "socket.http"; 106 function fetch.http(url)
107 107 local http = require "socket.http";
108 local body, status = http.request(url); 108
109 if status == 200 then 109 local body, status = http.request(url);
110 return body; 110 if status == 200 then
111 end 111 return body;
112 return false, "HTTP status code: "..tostring(status); 112 end
113 return false, "HTTP status code: "..tostring(status);
114 end
115 else
116 function fetch.http(url)
117 return false, "Module not found. Re-squish with --use-http option to fetch it from "..url;
118 end
113 end 119 end
114 120
115 print_info("Writing "..out_fn.."..."); 121 print_info("Writing "..out_fn.."...");
116 local f = io.open(out_fn, "w+"); 122 local f = io.open(out_fn, "w+");
117 123

mercurial