summaryrefslogtreecommitdiff
path: root/activity.lua
diff options
context:
space:
mode:
Diffstat (limited to 'activity.lua')
-rwxr-xr-xactivity.lua42
1 files changed, 42 insertions, 0 deletions
diff --git a/activity.lua b/activity.lua
new file mode 100755
index 0000000..a97e79d
--- /dev/null
+++ b/activity.lua
@@ -0,0 +1,42 @@
+#!/usr/bin/lua
+local args = require "pl.lapp" [[
+Generates activity chart
+ -f (string default 'ansi') Output format of the chart
+ -y (optional number) Generate yearly chart for selected year
+ -A... (optional string) Author e-mail addresses to include in chart
+ -C... (optional string) Committer e-mail addresses to include in chart
+ <repos...> (optional string) Paths to repositories with activity
+
+By default, tool will generate a rolling chart for selected repositories. If no
+repositories were selected, current working directory will be tried.
+]]
+local generators = require "activity.generators"
+local git = require "activity.git"
+local ok, maybe_format = pcall(require, "activity.formats." .. args.f)
+if not ok then
+ io.stderr:write(("could not find specified format: %q\n\n"):format(args.f))
+ io.stderr:write(maybe_format, "\n")
+ os.exit(1)
+end
+local maybe_year = args.y or "rolling"
+if #args.repos < 1 then
+ table.insert(args.repos, ".")
+end
+local filter, by_author, by_committer
+if #args.A > 0 then
+ by_author = git.any_value_filter("author", args.A)
+end
+if #args.C > 0 then
+ by_committer = git.any_value_filter("committer", args.C)
+end
+if by_committer and by_author then
+ function filter (entry)
+ return by_author(entry) or by_committer(entry)
+ end
+end
+filter = filter or by_author or by_committer
+local errors, lookup = git.lookup(args.repos, filter)
+io.write(generators.generate_table(maybe_year, lookup, maybe_format))
+if errors then
+ os.exit(1)
+end