diff --git a/shard.lock b/shard.lock index 5fe71a5..b470aeb 100644 --- a/shard.lock +++ b/shard.lock @@ -8,3 +8,7 @@ shards: git: https://github.com/kanezoh/mechanize.cr.git version: 0.2.0 + version_from_shard: + git: https://github.com/hugopl/version_from_shard.git + version: 1.2.5 + diff --git a/shard.yml b/shard.yml index 279205d..1b66e53 100644 --- a/shard.yml +++ b/shard.yml @@ -16,6 +16,8 @@ dependencies: mechanize: github: Kanezoh/mechanize.cr version: "~> 0.2.0" + version_from_shard: + github: hugopl/version_from_shard # dependencies: # pg: diff --git a/src/cli.cr b/src/cli.cr new file mode 100644 index 0000000..35111ee --- /dev/null +++ b/src/cli.cr @@ -0,0 +1,66 @@ +require "./config" +require "./version" +require "./providers/signal_spam" + +require "http/client" +require "option_parser" +require "file_utils" +require "mechanize" + +# Classe pour gérer les interactions avec Signal-Spam +module BulkBarrage + class Cli + def initialize + @option_parser = OptionParser.new do |parser| + parser.banner = [ + "#{PROGRAM_NAME} v#{VERSION}", + "Usage: bulkbarrage [options] [command] [args]" + ].join("\n") + + parser.on("configure", "Initialize the configuration") do + init_config + end + parser.on("report", "Process and report spam email (default: from STDIN)") do + process_email_spam + end + parser.on("--help", "-h", "show this help") do + puts parser + end + end + end + + def parse_arguments(args : Array(String)) + @option_parser.parse(args) + rescue e : OptionParser::Exception + puts e.message + puts @option_parser + exit(1) + end + + + private def init_config + print "Enter username: " + username = gets.try &.strip || "anonymous" + print "Enter password: " + password = gets.try &.strip || "anonymous" + create_config_file(username, password) + puts "Configuration file created." + end + + private def process_email_spam + email_spam = STDIN.gets_to_end + + signalspam = Providers::SignalSpam.new + signalspam.process(email_spam) + + puts "Email spam processed." + end + + private def create_config_file(username : String, password : String) + signalspam = Providers::SignalSpam.new + signalspam.create_config_file(username, password) + end + + end +end + diff --git a/src/main.cr b/src/main.cr index bb78029..e5b86f3 100644 --- a/src/main.cr +++ b/src/main.cr @@ -1,69 +1,4 @@ -require "./config" -require "./providers/signal_spam" +require "./cli" -require "http/client" -require "option_parser" -require "file_utils" -require "mechanize" - -# Nom du script et version -SCRIPT_NAME = "BulkBarrage" -SCRIPT_VERSION = "0.1.0" - -# Classe pour gérer les interactions avec Signal-Spam -class SignalSpamCtl - def initialize - @option_parser = OptionParser.new do |parser| - parser.banner = [ - "#{SCRIPT_NAME} v#{SCRIPT_VERSION}", - "Usage: bulkbarrage [options] [command] [args]" - ].join("\n") - - parser.on("configure", "Initialise the configuration") do - init_config - end - parser.on("report", "Process and report spam email (default: from STDIN)") do - process_email_spam - end - parser.on("--help", "-h", "show this help") do - puts parser - end - end - end - - def parse_arguments(args : Array(String)) - @option_parser.parse(args) - rescue e : OptionParser::Exception - puts e.message - puts @option_parser - exit(1) - end - - - private def init_config - print "Enter username: " - username = gets.try &.strip || "anonymous" - print "Enter password: " - password = gets.try &.strip || "anonymous" - create_config_file(username, password) - puts "Configuration file created." - end - - private def process_email_spam - email_spam = STDIN.gets_to_end - - signalspam = Providers::SignalSpam.new - signalspam.process(email_spam) - - puts "Email spam processed." - end - - private def create_config_file(username : String, password : String) - signalspam = Providers::SignalSpam.new - signalspam.create_config_file(username, password) - end - -end - -client = SignalSpamCtl.new +client = BulkBarrage::Cli.new client.parse_arguments(ARGV) diff --git a/src/version.cr b/src/version.cr index e8b96f0..6000e06 100644 --- a/src/version.cr +++ b/src/version.cr @@ -1,4 +1,11 @@ +require "version_from_shard" + +module BulkBarrage + PROGRAM_NAME = "BulkBarrage" + VersionFromShard.declare +end + # Nom du script et version -SCRIPT_NAME = "SignalSpamReporter" -SCRIPT_VERSION = "1.2" +# SCRIPT_NAME = "SignalSpamReporter" +# SCRIPT_VERSION = "1.2"