From ad90dff93fb24df33ea8c5c536248b01cadfc716 Mon Sep 17 00:00:00 2001 From: David Wilkie Date: Sat, 12 Oct 2024 10:36:53 +0700 Subject: [PATCH] fix: Update CLI --- skyetel/README.md | 5 ++++- skyetel/bin/somleng-skyetel | 13 +++++++++++-- skyetel/examples/README.md | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/skyetel/README.md b/skyetel/README.md index e2cd64c..77123ce 100644 --- a/skyetel/README.md +++ b/skyetel/README.md @@ -26,7 +26,10 @@ See [examples](https://github.com/somleng/somleng-integrations/tree/develop/skye The CLI can be used to test your integration or in standalone mode. ```bash -./bin/somleng-skyetel +Usage: somleng-skyetel [options] + --[no-]dry-run [FLAG] Dry run only. No phone numbers will be actually purchased. + --[no-]verbose [FLAG] Run verbosely + -h, --help Prints this help ``` ## Deployment diff --git a/skyetel/bin/somleng-skyetel b/skyetel/bin/somleng-skyetel index 42bb923..fa6198f 100755 --- a/skyetel/bin/somleng-skyetel +++ b/skyetel/bin/somleng-skyetel @@ -4,11 +4,12 @@ require "bundler/setup" require "optparse" require_relative "../config/application" +require "pry" class OptionsParser class MissingArgumentError < StandardError; end - Options = Struct.new(:dry_run, :verbose) + Options = Struct.new(:dry_run, :verbose, :help) attr_reader :parser, :options @@ -19,6 +20,8 @@ class OptionsParser def parse parser.parse! + return options if options.help + check_environment!("APP_ENV", "SOMLENG_API_KEY", "SKYETEL_USERNAME", "SKYETEL_PASSWORD", "MIN_STOCK", "MAX_STOCK") options end @@ -40,13 +43,19 @@ class OptionsParser opts.banner = "Usage: somleng-skyetel [options]" opts.on("--[no-]dry-run [FLAG]", "Dry run only. No phone numbers will be actually purchased.", TrueClass) { |o| options.dry_run = o.nil? ? true : o } opts.on("--[no-]verbose [FLAG]", "Run verbosely", TrueClass) { |o| options.verbose = o.nil? ? true : o } + opts.on("-h", "--help", "Prints this help", TrueClass) { |o| options.help = o.nil? ? true : o } end end end def parse_options parser = OptionsParser.new - parser.parse + options = parser.parse + if options.help + puts parser.help + exit(0) + end + options rescue OptionsParser::MissingArgumentError => e puts e.message puts parser.help diff --git a/skyetel/examples/README.md b/skyetel/examples/README.md index 6b5b56f..8427745 100644 --- a/skyetel/examples/README.md +++ b/skyetel/examples/README.md @@ -14,7 +14,7 @@ The image is ready to be deployed to AWS Lambda and can be triggered by a schedu ## Standalone mode -If you're not using Lambda, you can run your image with the following command. +If you're not using Lambda, you can run your image with the following command: ```bash docker run --platform linux/amd64 --rm -it -e APP_ENV=production -e SOMLENG_API_KEY='somleng-carrier-api-key' SOMLENG_API_KEY='somleng-carrier-api-key' -e SKYETEL_USERNAME='skyetel-username' -e SKYETEL_PASSWORD='skyetel-password' -e MIN_STOCK=5 -e MAX_STOCK=10 --entrypoint ./bin/somleng-skyetel somleng-skyetel:example