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
Mitchell Stanley committed Oct 20, 2020
2 parents 52d5f1a + c12d409 commit ec21e60
Show file tree
Hide file tree
Showing 17 changed files with 159 additions and 154 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.35.1
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM crystallang/crystal:0.35.1-alpine
RUN apk add --update --no-cache --force-overwrite \
openssl-libs-static openssl-dev g++ gc-dev \
libc-dev libevent-dev libevent-static libxml2-dev llvm llvm-dev \
llvm-static make pcre-dev readline-dev readline-static \
yaml-dev zlib-dev zlib-static ncurses-static sqlite-dev sqlite-static openssl-dev
#ncurses-libs ncurses-dev

13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ 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.35.1 to be installed to install from source

```bash
# Clone the repo
git clone [email protected]:snipline/snipcli.git
# Checkout the latest release
git checkout <tagname - e.g. 0.3.1>
git checkout <tagname - e.g. 0.4.0>
# Make sure you have the same Crystal installed that's required in shard.yml
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 @@ -128,11 +128,12 @@ As of 0.3.0 the web interface has been removed infavour of the new TUI.

See the Installation section on building from source.

Set log levels for additional development output.
Set log levels for additional development output and specifiy different config files for testing

```bash
crystal build src/snipline_cli.cr -o snipcli
env LOG_LEVEL=DEBUG ./snipcli search git
env CONFIG_FILE=~/.config/snipline/config.dev.toml ./snipcli search login
env CONFIG_FILE=~/.config/snipline/config.dev.toml env CRYSTAL_LOG_LEVEL=INFO ./snipcli search git
```

To change the config file location (For testing) use the `CONFIG_FILE` environment variable.
Expand Down
46 changes: 25 additions & 21 deletions shard.lock
Original file line number Diff line number Diff line change
@@ -1,42 +1,46 @@
version: 1.0
version: 2.0
shards:
admiral:
github: jwaldrip/admiral.cr
version: 1.9.0
git: https://github.com/jwaldrip/admiral.cr.git
version: 1.11.2

ameba:
github: veelenga/ameba
version: 0.11.0
git: https://github.com/veelenga/ameba.git
version: 0.13.2

crecto:
github: Crecto/crecto
version: 0.11.2
git: https://github.com/Crecto/crecto.git
version: 0.11.3

crest:
github: mamantoha/crest
version: 0.22.0
git: https://github.com/mamantoha/crest.git
version: 0.26.1

db:
github: crystal-lang/crystal-db
version: 0.7.0
git: https://github.com/crystal-lang/crystal-db.git
version: 0.9.0

fuzzy_match:
github: acoustep/fuzzy_match.cr
commit: fe9eed429118adc8f0f9f6c91de4f11cdca5840e
git: https://github.com/acoustep/fuzzy_match.cr.git
version: 0.3.0+git.commit.3834b23deab80c4554ce15b015b804f010e2b768

http-client-digest_auth:
github: mamantoha/http-client-digest_auth
version: 0.3.0
git: https://github.com/mamantoha/http-client-digest_auth.git
version: 0.4.0

http_proxy:
git: https://github.com/mamantoha/http_proxy.git
version: 0.7.1

ncurses:
github: JohnDowson/ncurses
commit: d0e46f673b6a443255269ce610d598a0fdc7d159
git: https://github.com/JohnDowson/ncurses.git
version: 0.0.3+git.commit.d0e46f673b6a443255269ce610d598a0fdc7d159

sqlite3:
github: crystal-lang/crystal-sqlite3
version: 0.14.0
git: https://github.com/crystal-lang/crystal-sqlite3.git
version: 0.16.0

toml:
github: crystal-community/toml.cr
commit: d02de85eed68a70dc97ab6d6e52831a4d0e890fe
git: https://github.com/crystal-community/toml.cr.git
version: 0.6.1+git.commit.d02de85eed68a70dc97ab6d6e52831a4d0e890fe

11 changes: 6 additions & 5 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.36.0

license: MIT

Expand All @@ -17,7 +17,7 @@ dependencies:
github: jwaldrip/admiral.cr
crest:
github: mamantoha/crest
version: ~> 0.22.0
version: ~> 0.26.1
toml:
github: crystal-community/toml.cr
branch: master
Expand All @@ -26,9 +26,10 @@ dependencies:
branch: borders_and_lines
crecto:
github: Crecto/crecto
version: ~> 0.11.3
sqlite3:
github: crystal-lang/crystal-sqlite3
version: ~> 0.14.0
version: ~> 0.16.0
fuzzy_match:
github: acoustep/fuzzy_match.cr
branch: master
Expand All @@ -38,4 +39,4 @@ dependencies:
development_dependencies:
ameba:
github: veelenga/ameba
version: ~> 0.11.0
version: ~> 0.13.2
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
62 changes: 36 additions & 26 deletions src/snipline_cli/commands/login.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,52 @@ 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."
Log.debug { "Test debug" }
print "Email:"
email = gets
spawn do
Crest.post(
"#{config.get("api.url")}/sessions",
form: {:email => email}
)
end
puts "Thanks, we're sending you a verification code..."
sleep 1
puts "Please enter the verification code that was sent to your email:"
print "Verification Code:"
verification_code = gets
log.debug("verification_code: #{verification_code}")
if verification_code.nil? || verification_code.empty?
puts "Code not entered. Please try again."
# spawn do
# Crest.post(
# "#{config.get("api.url")}/sessions",
# form: {:email => email}
# )
# end
print "Enter your Snipline Account password:"
# password = gets
password = STDIN.noecho &.gets.try &.chomp
password = password.as?(String) || ""

Log.debug {

password_length = password.size
hidden_password = password.chars.map_with_index { |c, i|
if i == 0 || i == (password_length - 1)
c
else
'*'
end
}.to_s

"password: #{hidden_password}"
}
if password.empty?
puts "Password not entered. Please try again."
return
end
puts ""
puts "One moment..."
puts "URL: #{config.get("api.url")}"
begin
Crest.post(
"#{config.get("api.url")}/tokens/create",
"#{config.get("api.url")}/v2/sessions",
form: {
:id => email,
:token => verification_code,
:length => "year",
:email => email,
:password => password
}
) 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 All @@ -68,13 +79,12 @@ module SniplineCli
end
rescue ex : Crest::NotFound
puts "404 Not Found :("
ex.response
rescue ex : Crest::InternalServerError
puts "Internal server error"
ex.response
rescue ex : Crest::Forbidden
puts "Incorrect Token"
ex.response
puts "Incorrect password"
rescue
puts "Unknown error"
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/snipline_cli/models/snippet.cr
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module SniplineCli::Models
param_name = split_equals.shift
unparsed_params = split_equals.join("=")
if unparsed_params.is_a?(String)
options = unparsed_params.split(",").map(&.strip)
options = unparsed_params.gsub("\\,", "###COMMA###").split(",").map(&.gsub("###COMMA###", ",")).map(&.strip)
# todo
if options.is_a?(Array(String))
options = options.as(Array(String))
Expand Down
36 changes: 22 additions & 14 deletions src/snipline_cli/parsers/snippet_data_parser.cr
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
module SniplineCli::Parsers
class SnippetDataParser
JSON.mapping({
data: Array(SnippetParser),
})
include JSON::Serializable

@[JSON::Field(key: "data")]
property data : Array(SnippetParser)
end

class SingleSnippetDataParser
JSON.mapping({
data: SnippetParser,
})
include JSON::Serializable

@[JSON::Field(key: "data")]
property data : SnippetParser
end

class SnippetError
JSON.mapping({
detail: String,
source: Hash(String, String),
title: String,
})
include JSON::Serializable

@[JSON::Field(key: "detail")]
property detail : String

@[JSON::Field(key: "source")]
property source : Hash(String, String)

@[JSON::Field(key: "title")]
property title : String
end

class SnippetErrorResponse
JSON.mapping({
errors: Array(SnippetError),
})
include JSON::Serializable

@[JSON::Field(key: "errors")]
property errors : Array(SnippetError)

def has_key?(key)
@errors.any? { |error|
Expand Down
21 changes: 16 additions & 5 deletions src/snipline_cli/parsers/snippet_parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,22 @@ module SniplineCli::Parsers
#
# Note how most attributes are contained within the `attribute` attribute. This is to conform to the JSON-API specification.
class SnippetParser
JSON.mapping({
id: String | Nil,
type: String,
attributes: SnippetAttributeParser,
})
include JSON::Serializable

@[JSON::Field(key: "id")]
property id : String | Nil

@[JSON::Field(key: "type")]
property type : String

@[JSON::Field(key: "attributes")]
property attributes : SnippetAttributeParser

# JSON.mapping({
# id: String | Nil,
# type: String,
# attributes: SnippetAttributeParser,
# })

def initialize(@id : String | Nil, @type : String, @attributes : SnippetAttributeParser)
end
Expand Down
Loading

0 comments on commit ec21e60

Please sign in to comment.