From 796162f0d42aa104327c041f910b5922746f6aad Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 12 Sep 2023 23:20:35 +0200 Subject: Extended the CLI with more traditional option handling --- activity/formats/ansi.lua | 58 +++++++++++++++++++++++++++++++++++++++++++++++ generate.lua | 12 ++++++---- 2 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 activity/formats/ansi.lua diff --git a/activity/formats/ansi.lua b/activity/formats/ansi.lua new file mode 100644 index 0000000..dae5bcb --- /dev/null +++ b/activity/formats/ansi.lua @@ -0,0 +1,58 @@ +local ansi = {} + + +function ansi.start_document (_) + return "" +end + + +function ansi.end_document () + return "" +end + + +function ansi.start_table () + return "" +end + + +function ansi.end_table () + return "" +end + + +function ansi.start_row () + return "" +end + + +function ansi.end_row () + return "\n" +end + + +function ansi.label (name) + return ("%5s "):format(name) +end + + +function ansi.spot () + return " " +end + + +local colours = { + [0] = "238", + "22", + "28", + "34", + "46", +} + + +function ansi.cell (level) + return ("\27[38;5;%dm"):format(colours[level]) .. "◼" .. "\27[0m" +end + + +return ansi diff --git a/generate.lua b/generate.lua index c9a21bf..02d46a8 100644 --- a/generate.lua +++ b/generate.lua @@ -1,5 +1,9 @@ +local args = require "pl.lapp" [[ +Generates activity chart + -f (string default 'ansi') Output format of the chart + -y (optional number) Year of the chart + (optional string) Paths to repositories with activity +]] local activity = require "activity" -local format = require "activity.formats.html5" -local args = {...} -local year = tonumber(table.remove(args, 1)) -print(activity.generate_table(year, args, format)) +local format = require("activity.formats." .. args.f) +io.write(activity.generate_table(args.y, args.repos, format)) -- cgit v1.1