<commit_before>--[[

Copyright 2014 The Luvit Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS-IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

--]]

local luvi = require('luvi')
local bundle = luvi.bundle

-- Manually register a couple modules in lua's require to bootstrap things
bundle.register("require", "modules/require.lua");
bundle.register("utils", "modules/utils.lua");
-- Upgrade require system in-place
local require = require('require')()("bundle:modules/main.lua")


local uv = require('uv')
local utils = require('utils')

local startRepl = nil
local combo = nil
local script = nil
local extra = {}

local function usage()
  print("Usage: " .. args[0] .. " [options] script.lua [arguments]"..[[


Options:
  -h, --help          Print this help screen.
  -v, --version       Print the version.
  -e code_chunk       Evaluate code chunk and print result.
  -i, --interactive   Enter interactive repl after executing script.
  -n, --no-color      Disable colors.
                      (Note, if no script is provided, a repl is run instead.)
]])
  startRepl = false
end

local function version()
  print("TODO: show luvit version")
  startRepl = false
end


local shorts = {
  h = "help",
  v = "version",
  e = "eval",
  i = "interactive",
  n = "no-color"
}

local flags = {
  help = usage,
  version = version,
  eval = function ()
    local repl = require('repl')(utils.stdin, utils.stdout)
    combo = repl.evaluateLine
    startRepl = false
  end,
  interactive = function ()
    startRepl = true
  end,
  ["no-color"] = function ()
    utils.loadColors(false)
  end
}

for i = 1, #args do
  local arg = args[i]
  if script then
    extra[#extra + 1] = arg
  elseif combo then
    combo(arg)
    combo = nil
  elseif string.sub(arg, 1, 1) == "-" then
    local flag
    if (string.sub(arg, 2, 2) == "-") then
      flag = string.sub(arg, 3)
    else
      flag = shorts[string.sub(arg, 2)]
    end
    flags[flag]()
  else
    script = arg
  end
end

if combo then error("Missing flag value") end

if startRepl == nil and not script then startRepl = true end

if script then
  loadfile(luvi.path.join(uv.cwd(), script))(unpack(extra))
end

if startRepl then
  local c = utils.color
  local greeting = "Welcome to the " .. c("Bred") .. "L" .. c("Bgreen") .. "uv" .. c("Bblue") .. "it" .. c() .. " repl!"
  require('repl')(utils.stdin, utils.stdout, greeting, ...).start()
end

-- Start the event loop
uv.run()

-- When the loop exits, close all uv handles.
uv.walk(uv.close)
uv.run()
<commit_msg>No need to register utils in bootstrap<commit_after>--[[

Copyright 2014 The Luvit Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS-IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

--]]

local luvi = require('luvi')
local bundle = luvi.bundle

-- Manually register a couple modules in lua's require to bootstrap things
bundle.register("require", "modules/require.lua");
-- Upgrade require system in-place
local require = require('require')()("bundle:modules/main.lua")


local uv = require('uv')
local utils = require('utils')

local startRepl = nil
local combo = nil
local script = nil
local extra = {}

local function usage()
  print("Usage: " .. args[0] .. " [options] script.lua [arguments]"..[[


Options:
  -h, --help          Print this help screen.
  -v, --version       Print the version.
  -e code_chunk       Evaluate code chunk and print result.
  -i, --interactive   Enter interactive repl after executing script.
  -n, --no-color      Disable colors.
                      (Note, if no script is provided, a repl is run instead.)
]])
  startRepl = false
end

local function version()
  print("TODO: show luvit version")
  startRepl = false
end


local shorts = {
  h = "help",
  v = "version",
  e = "eval",
  i = "interactive",
  n = "no-color"
}

local flags = {
  help = usage,
  version = version,
  eval = function ()
    local repl = require('repl')(utils.stdin, utils.stdout)
    combo = repl.evaluateLine
    startRepl = false
  end,
  interactive = function ()
    startRepl = true
  end,
  ["no-color"] = function ()
    utils.loadColors(false)
  end
}

for i = 1, #args do
  local arg = args[i]
  if script then
    extra[#extra + 1] = arg
  elseif combo then
    combo(arg)
    combo = nil
  elseif string.sub(arg, 1, 1) == "-" then
    local flag
    if (string.sub(arg, 2, 2) == "-") then
      flag = string.sub(arg, 3)
    else
      flag = shorts[string.sub(arg, 2)]
    end
    flags[flag]()
  else
    script = arg
  end
end

if combo then error("Missing flag value") end

if startRepl == nil and not script then startRepl = true end

if script then
  loadfile(luvi.path.join(uv.cwd(), script))(unpack(extra))
end

if startRepl then
  local c = utils.color
  local greeting = "Welcome to the " .. c("Bred") .. "L" .. c("Bgreen") .. "uv" .. c("Bblue") .. "it" .. c() .. " repl!"
  require('repl')(utils.stdin, utils.stdout, greeting, ...).start()
end

-- Start the event loop
uv.run()

-- When the loop exits, close all uv handles.
uv.walk(uv.close)
uv.run()

{'fraction_non_alphanumeric': 0.1268581081081081, 'fraction_numerical': 0.0057432432432432436, 'mean_word_length': 3.0554794520547945, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2582789', 'n_tokens_mistral': 1920, 'n_tokens_neox': 1857, 'n_words': 686}