Skip to content

Commit

Permalink
Merge branch 'release/0.1.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitchell Stanley committed Jul 10, 2019
2 parents ae92565 + 653fdb9 commit a7b4c7a
Show file tree
Hide file tree
Showing 23 changed files with 57 additions and 57 deletions.
1 change: 1 addition & 0 deletions .crystal-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.29.0
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
crystal 0.29.0
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Snipline CLI is the command-line tool for [Snipline](https://snipline.io).

[![asciicast](https://asciinema.org/a/R5vM238erVaOo62TYvHceixz3.svg)](https://asciinema.org/a/R5vM238erVaOo62TYvHceixz3)
![SnipCLI Preview](https://f002.backblazeb2.com/file/ms-uploads/snipline/2019-07-10%2010.41.26.gif)

Snipline CLI allows you to search and run commands from your Snipline account directly through the command-line. It is also possible to use this for free without a Snipline account (See the documentation on using without a Snipline Account).

Expand All @@ -26,7 +26,7 @@ sudo snap install snipcli --beta

### From source

Snipline CLI requires Crystal 0.28.0 to be installed to install from source
Snipline CLI requires Crystal 0.29.0 to be installed to install from source

```bash
# Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "snipcli",
"version": "0.1.0",
"version": "0.1.5",
"main": "index.js",
"author": "Mitchell Stanley <[email protected]>",
"license": "MIT",
Expand Down
6 changes: 5 additions & 1 deletion shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ shards:
github: jwaldrip/admiral.cr
version: 1.8.0

ameba:
github: veelenga/ameba
version: 0.10.0

baked_file_system:
github: schovi/baked_file_system
version: 0.9.8

crest:
github: mamantoha/crest
version: 0.19.1
version: 0.20.0

exception_page:
github: crystal-loot/exception_page
Expand Down
11 changes: 8 additions & 3 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: snipline_cli
version: 0.1.4
version: 0.1.5

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

crystal: 0.28.0
crystal: 0.29.0

license: MIT

Expand All @@ -27,4 +27,9 @@ dependencies:
version: 0.9.8
spec-kemal:
github: kemalcr/spec-kemal
branch: master
branch: master

development_dependencies:
ameba:
github: veelenga/ameba
version: ~> 0.10.0
3 changes: 1 addition & 2 deletions spec/models/snippet_attribute_spec.cr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
describe SniplineCli::SnippetAttribute do
it "correctly parses snippets attributes" do
attributes = SniplineCli::SnippetAttribute.from_json(
%(
%(
{
"is-pinned": true,
"name": "Test",
Expand All @@ -18,4 +18,3 @@ describe SniplineCli::SnippetAttribute do
attributes.documentation.should eq nil
end
end

2 changes: 1 addition & 1 deletion spec/services/command_builder_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe SniplineCli::Services::CommandBuilder do
first_password = split[1]
# If the second half of the split also has the same password
# This checks if the password with the same name is repeating correctly.
"#{split[2]}".includes?(split[1])
"#{split[2]}".includes?(first_password)
end
end

Expand Down
4 changes: 2 additions & 2 deletions src/snipline_cli.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ require "./snipline_cli/commands/*"
require "toml"

module SniplineCli
VERSION = "0.1.4"
VERSION = "0.1.5"

def self.config
SniplineCli::Config.config
end

def self.config_file
ENV.has_key?("CONFIG_FILE") ? ENV["CONFIG_FILE"] : "~/.config/snipline/config.toml"
ENV.has_key?("CONFIG_FILE") ? ENV["CONFIG_FILE"] : "~/.config/snipline/config.toml"
end

def self.log
Expand Down
2 changes: 0 additions & 2 deletions src/snipline_cli/commands/init.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ require "toml"

module SniplineCli
class Command < Admiral::Command

# The command to initialize Snipline CLI without an active Snipline account.
#
# This command generates a config file in the requested location.
Expand Down Expand Up @@ -34,4 +33,3 @@ module SniplineCli
register_sub_command :init, Init
end
end

1 change: 0 additions & 1 deletion src/snipline_cli/commands/login.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ require "toml"

module SniplineCli
class Command < Admiral::Command

# The command to initialize Snipline CLI _with_ an active Snipline account.
#
# This command generates a config file in the requested location.
Expand Down
34 changes: 19 additions & 15 deletions src/snipline_cli/commands/search.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ require "toml"

module SniplineCli
class Command < Admiral::Command

# The command to search your snippets.
#
# You can search snippets quickly by using
Expand Down Expand Up @@ -35,9 +34,6 @@ module SniplineCli
property results

def run
config = SniplineCli.config
log = SniplineCli.log

search_term : String = arguments.search_term || ""

snippets = SniplineCli::Services::LoadSnippets.run
Expand All @@ -57,17 +53,7 @@ module SniplineCli
}
end

results = snippets.sort { |snippet_a, snippet_b|
if snippet_a.is_pinned && snippet_b.is_pinned
snippet_a.name <=> snippet_b.name
elsif snippet_a.is_pinned
-1
elsif snippet_b.is_pinned
1
else
snippet_a.name <=> snippet_b.name
end
}.first(flags.limit)
results = sort_results(snippets, flags.limit)

unless results.size > 0
puts "No results found."
Expand All @@ -82,6 +68,24 @@ module SniplineCli
puts "\nChoose a snippet"
chosen_snippet_index = gets

handle_chosen_snippet(chosen_snippet_index, results)
end

def sort_results(snippets, limit)
snippets.sort { |snippet_a, snippet_b|
if snippet_a.is_pinned && snippet_b.is_pinned
snippet_a.name <=> snippet_b.name
elsif snippet_a.is_pinned
-1
elsif snippet_b.is_pinned
1
else
snippet_a.name <=> snippet_b.name
end
}.first(limit)
end

def handle_chosen_snippet(chosen_snippet_index, results)
if chosen_snippet_index
if chosen_snippet_index.to_i?
chosen_snippet_index = (chosen_snippet_index.to_u32 - 1)
Expand Down
3 changes: 1 addition & 2 deletions src/snipline_cli/commands/web.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ require "file"

module SniplineCli
class Command < Admiral::Command

# The command to start the web version of Snipline CLI
#
# ```bash
Expand All @@ -21,7 +20,7 @@ module SniplineCli

def run
# add_context_storage_type([] of SniplineCli::Snippet)
get "/" do |env|
get "/" do
# env.set "snippets", snippets
render "src/snipline_cli/templates/index.ecr", "src/snipline_cli/templates/layout.ecr"
end
Expand Down
1 change: 0 additions & 1 deletion src/snipline_cli/config/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module SniplineCli
# config.get("api.url")
# ```
class Config

# Constant that creates a fresh version of itself - for use with self.config.
INSTANCE = Config.new

Expand Down
4 changes: 2 additions & 2 deletions src/snipline_cli/models/snippet.cr
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module SniplineCli

real_command.scan(/#(select)?\{\[(.+?)\]\}/) do |m|
param_type = (m[1]?) ? m[1] : "variable"
if temp_array.select { |param| param.name == m[2] && param_type == param.type }.size == 0
if temp_array.count { |param| param.name == m[2] && param_type == param.type } == 0
if param_type == "select"
split_equals = m[2].split("=").map { |substring| substring }
param_name = split_equals.shift
Expand All @@ -70,7 +70,7 @@ module SniplineCli
end
end
end
return temp_array
temp_array
end

#
Expand Down
1 change: 0 additions & 1 deletion src/snipline_cli/models/token.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ module SniplineCli

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

end
end
10 changes: 4 additions & 6 deletions src/snipline_cli/services/command_builder.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module SniplineCli
module Services

# Takes a `Snippet`, asks for users parameter changes, and then returns the output as a string.
#
# ```crystal
Expand All @@ -15,14 +14,13 @@ module SniplineCli
# end
# ```
class CommandBuilder

def self.run(snippet : Snippet, input, output, user_input = [] of String) : String
unless snippet.has_params
return snippet.real_command
end

command_builder = snippet.real_command
snippet.interactive_params.each_with_index do |param, index|
snippet.interactive_params.each do |param|
case param.type
when "select"
print("Choose number for #{param.name}:", output)
Expand Down Expand Up @@ -56,6 +54,7 @@ module SniplineCli
end
end

# ameba:disable Lint/PercentArrays
password_characters = %w{a b c d e f g h i j k l m n o
p q r s t u v w x y z A B C D
E F G H I J K L M N O P Q R S
Expand Down Expand Up @@ -85,11 +84,11 @@ module SniplineCli
end

# Handles user input. If an array of is pre-supplied (E.g. for tests) then they are used.
# Otherwise user is asked to input the variables in the terminal.
# Otherwise user is asked to input the variables in the terminal.
private def self.gets(output, override_input : String | Nil, *args)
case override_input
when String
return override_input
override_input
else
output.gets(*args)
end
Expand All @@ -104,7 +103,6 @@ module SniplineCli
{nil, user_input}
end
end

end
end
end
18 changes: 9 additions & 9 deletions src/snipline_cli/services/create_config_directory.cr
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module SniplineCli
module Services
class CreateConfigDirectory
def self.run(file)
directory_name = File.expand_path(File.dirname(file))
unless File.directory?(directory_name)
SniplineCli.log.debug("Making config directory #{directory_name}")
Dir.mkdir(directory_name)
end
end
module Services
class CreateConfigDirectory
def self.run(file)
directory_name = File.expand_path(File.dirname(file))
unless File.directory?(directory_name)
SniplineCli.log.debug("Making config directory #{directory_name}")
Dir.mkdir(directory_name)
end
end
end
end
end
1 change: 0 additions & 1 deletion src/snipline_cli/services/file_storage.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ require "baked_file_system"

module SniplineCli
module Services

# FileStorage is used for baking in web assets into the final executable.
class FileStorage
extend BakedFileSystem
Expand Down
1 change: 0 additions & 1 deletion src/snipline_cli/services/load_snippets.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module SniplineCli
module Services

# LoadSnippets fetches all the snippets from the `snippet.json` file and parses them.
#
# ```crystal
Expand Down
1 change: 0 additions & 1 deletion src/snipline_cli/services/log.cr
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ module SniplineCli
# env LOG_LEVEL=WARN snipcli sync
# ```
class Log

# Constant that creates a fresh version of itself - for use with self.log.
INSTANCE = Log.new

Expand Down
1 change: 0 additions & 1 deletion src/snipline_cli/services/snipline_api.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ require "json"
module SniplineCli::Services
# For talking to the Snipline API.
class SniplineApi

# Fetches the user's Snippets.
def fetch(&block)
config = SniplineCli.config
Expand Down
2 changes: 0 additions & 2 deletions src/snipline_cli/services/store_snippets.cr
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
require "json"

module SniplineCli::Services

# For saving Snippets locally.
class StoreSnippets

# Takes an array of snippets and saves them to the `snippet.json` file.
def store(snippets)
config = SniplineCli.config
Expand Down

0 comments on commit a7b4c7a

Please sign in to comment.