Skip to content

Commit

Permalink
Merge branch 'release/0.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
acoustep committed May 9, 2020
2 parents 52d5f1a + 06a461e commit adc2113
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 92 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
crystal 0.32.1
crystal 0.34.0
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,9 +37,9 @@ git checkout <tagname - e.g. 0.3.1>
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
```
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@ 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
version: 0.11.2

crest:
github: mamantoha/crest
version: 0.22.0
version: 0.25.0

db:
github: crystal-lang/crystal-db
version: 0.7.0

fuzzy_match:
github: acoustep/fuzzy_match.cr
commit: fe9eed429118adc8f0f9f6c91de4f11cdca5840e
commit: 3834b23deab80c4554ce15b015b804f010e2b768

http-client-digest_auth:
github: mamantoha/http-client-digest_auth
Expand Down
8 changes: 4 additions & 4 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: cli
version: 0.3.3
version: 0.4.0

authors:
- Mitchell Stanley <[email protected]>
Expand All @@ -8,7 +8,7 @@ targets:
cli2:
main: src/cli.cr

crystal: < 0.33
crystal: 0.34.0

license: MIT

Expand All @@ -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
Expand All @@ -38,4 +38,4 @@ dependencies:
development_dependencies:
ameba:
github: veelenga/ameba
version: ~> 0.11.0
version: ~> 0.12.1
2 changes: 1 addition & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
9 changes: 4 additions & 5 deletions src/snipline_cli.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ require "json"
require "ncurses"
require "sqlite3"
require "crecto"
require "log"

require "./snipline_cli/config"
require "./snipline_cli/helpers/*"
Expand All @@ -17,6 +18,8 @@ require "./snipline_cli/commands/*"

include SniplineCli::Services

Log.setup_from_env

module Repo
extend Crecto::Repo

Expand All @@ -27,7 +30,7 @@ module Repo
end

module SniplineCli
VERSION = "0.3.3"
VERSION = "0.4.0"

def self.config
Config.config
Expand All @@ -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
Expand Down
7 changes: 3 additions & 4 deletions src/snipline_cli/commands/login.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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:"
Expand All @@ -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
Expand All @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions src/snipline_cli/services/create_config_directory.cr
Original file line number Diff line number Diff line change
@@ -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
Expand Down
29 changes: 19 additions & 10 deletions src/snipline_cli/services/display_results.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions src/snipline_cli/services/edit_snippet.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ 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
system("#{ENV["EDITOR"]} #{SniplineCli::Helpers.expand_path("#{config.get("general.temp_dir")}/temp.toml")}")
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
Expand Down
5 changes: 2 additions & 3 deletions src/snipline_cli/services/load_snippets.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
47 changes: 0 additions & 47 deletions src/snipline_cli/services/log.cr
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions src/snipline_cli/services/snipline_api.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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!
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit adc2113

Please sign in to comment.