Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lapis/cmd/actions/annotate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ build_command = function(cmd, config)
do
local password = config.postgres.password
if password then
table.insert(1, command, "PGPASSWORD=" .. tostring(shell_escape(password)))
table.insert(command, 1, "PGPASSWORD=" .. tostring(shell_escape(password)))
end
end
do
Expand Down Expand Up @@ -229,8 +229,16 @@ annotate_model = function(config, fname, options)
end
local header = table.concat(header_lines, "\n") .. "\n"
local updated_source = replace_header(source, header)
if not (updated_source) then
updated_source = source:gsub("class ", tostring(header) .. "class ", 1)
if fname:match(".lua$") and not updated_source then
local lua_declaration = "local %w+ = Model:extend"
if not source:match(lua_declaration) then
print("\tLine matching '" .. tostring(lua_declaration) .. "' not found")
end
updated_source = source:gsub(lua_declaration, tostring(header) .. "%1 ", 1)
else
if not updated_source then
updated_source = source:gsub("class ", tostring(header) .. "class ", 1)
end
end
local source_out = assert(io.open(fname, "w"))
source_out:write(updated_source)
Expand Down
10 changes: 7 additions & 3 deletions lapis/cmd/actions/annotate.moon
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ build_command = (cmd, config) ->
command = { cmd }

if password = config.postgres.password
table.insert 1, command, "PGPASSWORD=#{shell_escape password}"
table.insert command, 1, "PGPASSWORD=#{shell_escape password}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should have made this a separate PR (happy to, if helpful) but this seems like a genuine typo. :)


if host = config.postgres.host
table.insert command, "-h #{shell_escape host}"
Expand Down Expand Up @@ -149,8 +149,12 @@ annotate_model = (config, fname, options={}) ->

updated_source = replace_header source, header

-- TODO: this is kinda sloppy and only works with MoonScript
unless updated_source
-- TODO: this is kinda sloppy
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept the comment for no particular reason, but edited to at least not be false. 🙃

Obviously, this could be more flexible, but it does seem to work fine for now.

if fname\match(".lua$") and not updated_source
lua_declaration = "local %w+ = Model:extend"
print "\tLine matching '#{lua_declaration}' not found" if not source\match lua_declaration
updated_source = source\gsub lua_declaration, "#{header}%1 ", 1
else if not updated_source
updated_source = source\gsub "class ", "#{header}class ", 1

source_out = assert io.open fname, "w"
Expand Down