diff --git a/.tool-versions b/.tool-versions index 4991363..5e03da4 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -crystal 0.32.1 +crystal 0.34.0 diff --git a/README.md b/README.md index 538970a..3e28f87 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ sudo snap install snipcli --beta ### From source -Snipline CLI requires Crystal 0.30.1 to be installed to install from source +Snipline CLI requires Crystal 0.34.0 to be installed to install from source ```bash # Clone the repo @@ -37,9 +37,9 @@ git checkout crystal -v # Install dependencies shards -# Build app for Crystal 0.32.1 / MacOS +# Build app for Crystal 0.34.0 / MacOS crystal build src/snipline_cli.cr -o snipcli --release -o snipcli -# Build app for Crystal 0.31.1 / Linux (Alpine) +# Build app for Crystal 0.34.0 / Linux (Alpine) crystal build src/snipline_cli.cr -o snipcli --release -o snipcli -Dstatic_linux ./snipcli --version ``` @@ -132,7 +132,7 @@ Set log levels for additional development output. ```bash crystal build src/snipline_cli.cr -o snipcli -env LOG_LEVEL=DEBUG ./snipcli search git +env CRYSTAL_LOG_LEVEL=INFO ./snipcli search git ``` To change the config file location (For testing) use the `CONFIG_FILE` environment variable. diff --git a/shard.lock b/shard.lock index a1ec933..a86c3a8 100644 --- a/shard.lock +++ b/shard.lock @@ -2,11 +2,11 @@ version: 1.0 shards: admiral: github: jwaldrip/admiral.cr - version: 1.9.0 + version: 1.10.1 ameba: github: veelenga/ameba - version: 0.11.0 + version: 0.12.1 crecto: github: Crecto/crecto @@ -14,7 +14,7 @@ shards: crest: github: mamantoha/crest - version: 0.22.0 + version: 0.25.0 db: github: crystal-lang/crystal-db @@ -22,7 +22,7 @@ shards: fuzzy_match: github: acoustep/fuzzy_match.cr - commit: fe9eed429118adc8f0f9f6c91de4f11cdca5840e + commit: 3834b23deab80c4554ce15b015b804f010e2b768 http-client-digest_auth: github: mamantoha/http-client-digest_auth diff --git a/shard.yml b/shard.yml index 8774805..78cc9c9 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: cli -version: 0.3.3 +version: 0.4.0 authors: - Mitchell Stanley @@ -8,7 +8,7 @@ targets: cli2: main: src/cli.cr -crystal: < 0.33 +crystal: 0.34.0 license: MIT @@ -17,7 +17,7 @@ dependencies: github: jwaldrip/admiral.cr crest: github: mamantoha/crest - version: ~> 0.22.0 + version: ~> 0.25.0 toml: github: crystal-community/toml.cr branch: master @@ -38,4 +38,4 @@ dependencies: development_dependencies: ameba: github: veelenga/ameba - version: ~> 0.11.0 + version: ~> 0.12.1 diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index a648022..e6864f7 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,5 +1,5 @@ name: snipcli -version: 0.3.3 +version: 0.4.0 summary: Shell Snippet organiser description: > Snipcli is a commandline interface for managing shell commands. Sync commands with your Snipline account or use in guest mode. Snipline lets you dynamically change command parameters easily so you never have to remember how to build a command. diff --git a/src/snipline_cli.cr b/src/snipline_cli.cr index 82f90bf..a506f46 100644 --- a/src/snipline_cli.cr +++ b/src/snipline_cli.cr @@ -5,6 +5,7 @@ require "json" require "ncurses" require "sqlite3" require "crecto" +require "log" require "./snipline_cli/config" require "./snipline_cli/helpers/*" @@ -17,6 +18,8 @@ require "./snipline_cli/commands/*" include SniplineCli::Services +Log.setup_from_env + module Repo extend Crecto::Repo @@ -27,7 +30,7 @@ module Repo end module SniplineCli - VERSION = "0.3.3" + VERSION = "0.4.0" def self.config Config.config @@ -37,10 +40,6 @@ module SniplineCli ENV.has_key?("CONFIG_FILE") ? ENV["CONFIG_FILE"] : "~/.config/snipline/config.toml" end - def self.log - Log.log - end - # The base Command Class that inherits from [Admiral](https://github.com/jwaldrip/admiral.cr) # # This command is not used by itself diff --git a/src/snipline_cli/commands/login.cr b/src/snipline_cli/commands/login.cr index e341a47..eda2de3 100644 --- a/src/snipline_cli/commands/login.cr +++ b/src/snipline_cli/commands/login.cr @@ -14,7 +14,6 @@ module SniplineCli def run config = SniplineCli.config - log = SniplineCli.log puts "What's your Snipline email account?".colorize.mode(:bold) puts "Register at #{"https://account.snipline.io/register".colorize.mode(:underline)} if you don't have an account." print "Email:" @@ -30,7 +29,7 @@ module SniplineCli puts "Please enter the verification code that was sent to your email:" print "Verification Code:" verification_code = gets - log.debug("verification_code: #{verification_code}") + Log.debug { "verification_code: #{verification_code}" } if verification_code.nil? || verification_code.empty? puts "Code not entered. Please try again." return @@ -46,9 +45,9 @@ module SniplineCli :length => "year", } ) do |response| - log.debug("response body") + Log.debug { "response body" } json_string = response.body_io.gets_to_end - log.debug(json_string.inspect) + Log.debug { json_string.inspect } token = Token.from_json(json_string) toml_contents = <<-TOML title = "Snipline" diff --git a/src/snipline_cli/services/create_config_directory.cr b/src/snipline_cli/services/create_config_directory.cr index 7b4626c..ef31d6a 100644 --- a/src/snipline_cli/services/create_config_directory.cr +++ b/src/snipline_cli/services/create_config_directory.cr @@ -1,12 +1,13 @@ require "../helpers/*" + module SniplineCli module Services # Creates a config directory for storing configuration files for SnipCLI. class CreateConfigDirectory def self.run(file) - directory_name = SniplineCli::Helpers.expand_path(File.dirname(file)) + directory_name = SniplineCli::Helpers.expand_path(File.dirname(file)) unless File.directory?(directory_name) - SniplineCli.log.debug("Making config directory #{directory_name}") + Log.debug { "Making config directory #{directory_name}" } Dir.mkdir(directory_name) end end diff --git a/src/snipline_cli/services/display_results.cr b/src/snipline_cli/services/display_results.cr index b598469..77b4937 100644 --- a/src/snipline_cli/services/display_results.cr +++ b/src/snipline_cli/services/display_results.cr @@ -35,6 +35,7 @@ module SniplineCli::Services break if codepoint == 17 # C+q - quit break if run_character_key(ch, codepoint) == false @left_pane.filter(@search.search_text) + else end @search.window.refresh end @@ -54,19 +55,27 @@ module SniplineCli::Services @left_pane.select_lower refresh_right_pane elsif codepoint == 67 || codepoint == 10 # Shift+c / Enter - copy - output = build_snippet - copy_snippet(output) - return false + unless @left_pane.results.size <= 0 + output = build_snippet + copy_snippet(output) + return false + end elsif codepoint == 68 # Shift+d - delete - delete_snippet - return false + unless @left_pane.results.size <= 0 + delete_snippet + return false + end elsif codepoint == 69 # Shift+e - edit - edit_snippet - return false + unless @left_pane.results.size <= 0 + edit_snippet + return false + end elsif codepoint == 82 # Shift+r - run - output = build_snippet - run_snippet(output) - return false + unless @left_pane.results.size <= 0 + output = build_snippet + run_snippet(output) + return false + end else @search.write(ch) @left_pane.filter(@search.search_text) diff --git a/src/snipline_cli/services/edit_snippet.cr b/src/snipline_cli/services/edit_snippet.cr index 320a582..4c0cac0 100644 --- a/src/snipline_cli/services/edit_snippet.cr +++ b/src/snipline_cli/services/edit_snippet.cr @@ -10,8 +10,7 @@ module SniplineCli class EditSnippet def self.run(snippet : Snippet, input, output) config = SniplineCli.config - log = SniplineCli.log - log.info("editing snippet #{snippet.name}") + Log.info { "editing snippet #{snippet.name}" } temp_file = TempSnippetEditorFile.new(snippet) temp_file.create loop do @@ -19,8 +18,8 @@ module SniplineCli snippet_attributes = temp_file.read snippet.name = snippet_attributes.name snippet.real_command = snippet_attributes.real_command.strip - log.info(snippet.real_command.not_nil!) - log.info(snippet_attributes.real_command.not_nil!) + Log.info { snippet.real_command.not_nil! } + Log.info { snippet_attributes.real_command.not_nil! } snippet.documentation = snippet_attributes.documentation snippet.tags = (snippet_attributes.tags.nil?) ? nil : snippet_attributes.tags.not_nil!.join(",") snippet.snippet_alias = snippet_attributes.snippet_alias diff --git a/src/snipline_cli/services/load_snippets.cr b/src/snipline_cli/services/load_snippets.cr index 2486fde..64b4696 100644 --- a/src/snipline_cli/services/load_snippets.cr +++ b/src/snipline_cli/services/load_snippets.cr @@ -12,10 +12,9 @@ module SniplineCli class LoadSnippets def self.run : Array(Snippet) config = SniplineCli.config - log = SniplineCli.log - log.info("Looking through file #{config.get("general.db")}") + Log.info { "Looking through file #{config.get("general.db")}" } unless File.readable?(expand_path(config.get("general.db"))) - log.warn("Could not read #{config.get("general.db")}") + Log.warn { "Could not read #{config.get("general.db")}" } abort("Run #{"snipline-cli sync".colorize(:green)} first") end # File.open(File.expand_path(config.get("general.db"))) do |file| diff --git a/src/snipline_cli/services/log.cr b/src/snipline_cli/services/log.cr index ffadc3f..e69de29 100644 --- a/src/snipline_cli/services/log.cr +++ b/src/snipline_cli/services/log.cr @@ -1,47 +0,0 @@ -require "logger" - -module SniplineCli - module Services - # Log is a wrapper around the Crystal `Logger`. - # - # Example Usage - # - # ```crystal - # log = SniplineCli.log - # config = SniplineCli.config - # log.info("Looking through file #{config.get("general.file")}") - # ``` - # - # The output level can then be specified at run-time. - # - # ```bash - # env LOG_LEVEL=WARN snipcli sync - # ``` - class Log - # Constant that creates a fresh version of itself - for use with self.log. - INSTANCE = Log.new - - property logger : Logger - - def initialize - ENV["LOG_LEVEL"] ||= "WARN" - @logger = Logger.new(STDOUT, level: (ENV["LOG_LEVEL"] == "DEBUG") ? Logger::DEBUG : Logger::WARN) - end - - # The static convenience method for retreiving the Log class instance without regenerating it. - def self.log - Log::INSTANCE - end - - macro define_methods(names) - {% for name in names %} - def {{name}}(message : String) - @logger.{{name}}(message) - end - {% end %} - end - - define_methods([debug, warn, info, fatal]) - end - end -end diff --git a/src/snipline_cli/services/snipline_api.cr b/src/snipline_cli/services/snipline_api.cr index e2386d1..25b6b37 100644 --- a/src/snipline_cli/services/snipline_api.cr +++ b/src/snipline_cli/services/snipline_api.cr @@ -37,7 +37,7 @@ module SniplineCli::Services # :tags => snippet.tags # } }, - logging: ENV["LOG_LEVEL"] == "DEBUG" ? true : false + logging: ENV["CRYSTAL_LOG_LEVEL"] == "DEBUG" ? true : false ) SingleSnippetDataParser.from_json(resp.body).data end @@ -61,7 +61,7 @@ module SniplineCli::Services # :tags => snippet.tags # } }, - logging: ENV["LOG_LEVEL"] == "DEBUG" ? true : false + logging: ENV["CRYSTAL_LOG_LEVEL"] == "DEBUG" ? true : false ) response = SingleSnippetDataParser.from_json(resp.body).data snippet.name = response.name.not_nil! @@ -90,7 +90,7 @@ module SniplineCli::Services # "Accept" => "application/vnd.api+json", "Authorization" => "Bearer #{config.get("api.token")}", }, - logging: ENV["LOG_LEVEL"] == "DEBUG" ? true : false + logging: ENV["CRYSTAL_LOG_LEVEL"] == "DEBUG" ? true : false ) true rescue ex