lbq-cli 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/docs/index.html +150 -1
- data/lib/lbq/cli/version.rb +1 -1
- data/lib/lbq/cli.rb +4 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66a5ba81f5fbd6a6244a625a7c5bf94e6375629ed268952451d52aaae98c6fb0
|
4
|
+
data.tar.gz: 903186900b1bbef0a843b876326b310bcabb65d2d110382af61532a77d54ff2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7938e0ac10691b8cfa8dfefa592767e6b4195e3c9c8f1653d8bad7b983caa923324021c564b07711d1b328432a82557c77496e5de031064da358bce5597b2139
|
7
|
+
data.tar.gz: 022ef7fc725b69bb8f5d6ab3d374e5f112682ec0be99a05a37467a0073fb9002b790fb803f73563a98b952227e7354c4a3081b63fdd80cd615997f2f4ee2db55
|
data/docs/index.html
CHANGED
@@ -2,9 +2,158 @@
|
|
2
2
|
<html lang="en">
|
3
3
|
<head>
|
4
4
|
<meta charset="UTF-8">
|
5
|
+
<meta name="viewport" content="width=device-width">
|
5
6
|
<title>LBQ CLI</title>
|
7
|
+
<style>
|
8
|
+
* {
|
9
|
+
box-sizing: border-box;
|
10
|
+
}
|
11
|
+
body {
|
12
|
+
font-family: 'Microsoft Yahei UI Light', Segoe UI, sans-serif;
|
13
|
+
}
|
14
|
+
pre, code {
|
15
|
+
font-family: 'Courier New', monospace;
|
16
|
+
}
|
17
|
+
pre {
|
18
|
+
margin-top: 2.5em;
|
19
|
+
white-space: pre-wrap;
|
20
|
+
word-break: break-all;
|
21
|
+
padding: 8px;
|
22
|
+
position: relative;
|
23
|
+
box-shadow: 0 0 0 1px #0c0c0c inset;
|
24
|
+
font-size: 14px;
|
25
|
+
}
|
26
|
+
h1, h2 {
|
27
|
+
margin: 0;
|
28
|
+
padding: 8px;
|
29
|
+
color: #f2f2f2;
|
30
|
+
background-color: #0c0c0c;
|
31
|
+
font-size: 22px;
|
32
|
+
font-weight: normal;
|
33
|
+
font-family: 'Microsoft Yahei UI Light', Segoe UI, sans-serif;
|
34
|
+
}
|
35
|
+
h2 {
|
36
|
+
font-size: 16px;
|
37
|
+
}
|
38
|
+
pre::before {
|
39
|
+
content: attr(data-title);
|
40
|
+
position: absolute;
|
41
|
+
bottom: 100%;
|
42
|
+
left: 0;
|
43
|
+
padding: 4px 8px;
|
44
|
+
color: #f2f2f2;
|
45
|
+
background-color: #0c0c0c;
|
46
|
+
}
|
47
|
+
</style>
|
6
48
|
</head>
|
7
49
|
<body>
|
8
|
-
|
50
|
+
<h1>Example <code>LBQ-CLI</code> Scripts</h1>
|
51
|
+
<pre data-title="edit"><code>params do
|
52
|
+
option('--command', '-c', '--file', '-f', 'the script to edit', index: 0)
|
53
|
+
end
|
54
|
+
|
55
|
+
main do
|
56
|
+
if params[:c]
|
57
|
+
file = "#{params[:c]}.rb"
|
58
|
+
full_path = File.expand_path(file, __dir__)
|
59
|
+
unless File.exist? full_path
|
60
|
+
puts "Not found #{file}"
|
61
|
+
next
|
62
|
+
end
|
63
|
+
system 'subl', full_path
|
64
|
+
end
|
65
|
+
end</code></pre>
|
66
|
+
<pre data-title="fate luck"><code>params do
|
67
|
+
option('--command', '-c', 'luck', index: 0)
|
68
|
+
end
|
69
|
+
|
70
|
+
main do
|
71
|
+
case params[:c]
|
72
|
+
when 'luck'
|
73
|
+
luck = rand 0..100
|
74
|
+
progress = '|' * luck + ' ' * (100 - luck)
|
75
|
+
printf "%3d%% [%s]", luck, progress
|
76
|
+
puts
|
77
|
+
end
|
78
|
+
end</code></pre>
|
79
|
+
<pre data-title="todo"><code>class Storage
|
80
|
+
def initialize file
|
81
|
+
@file = file
|
82
|
+
end
|
83
|
+
|
84
|
+
def load_data
|
85
|
+
if File.exist? @file
|
86
|
+
open(@file, 'rb') { |f| Marshal.load f }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def save_data obj
|
91
|
+
open(@file, 'wb') { |f| Marshal.dump obj, f }
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
S = Storage.new File.expand_path 'todo.data', __dir__
|
96
|
+
|
97
|
+
params do
|
98
|
+
option('--task', '-t', 'what to do?', index: 0)
|
99
|
+
option('--edit', '-e', 'which to edit?', type: Integer)
|
100
|
+
switch('--edit', '-e', 'edit which?')
|
101
|
+
option('--delete', '-d', 'which to delete?', type: Integer)
|
102
|
+
switch('--delete', '-d', 'delete which?')
|
103
|
+
switch('--clear', '-c', 'remove all todos')
|
104
|
+
end
|
105
|
+
|
106
|
+
main do
|
107
|
+
data = S.load_data || []
|
108
|
+
if new_task = params[:t]
|
109
|
+
if old_task = params[:e]
|
110
|
+
data[old_task] = new_task
|
111
|
+
else
|
112
|
+
data << new_task
|
113
|
+
end
|
114
|
+
S.save_data data
|
115
|
+
elsif old_task = params[:d]
|
116
|
+
if old_task == true
|
117
|
+
puts 'Run "todo -d <id>" to delete task.'
|
118
|
+
else
|
119
|
+
data.delete_at old_task
|
120
|
+
S.save_data data
|
121
|
+
end
|
122
|
+
elsif old_task = params[:e]
|
123
|
+
if old_task == true
|
124
|
+
puts 'Run "todo -e <id> <todo>" to edit task.'
|
125
|
+
end
|
126
|
+
elsif params[:c]
|
127
|
+
S.save_data data.clear
|
128
|
+
end
|
129
|
+
data.each_with_index do |task, i|
|
130
|
+
puts "[#{i}] #{task}"
|
131
|
+
end
|
132
|
+
end</code></pre>
|
133
|
+
<h2>Windows Only <small>(Some of them can be easily converted to *NIX systems.)</small></h2>
|
134
|
+
<pre data-title="rerun">params do
|
135
|
+
option('--file', '--dir', '-d', '--watch', '-w', index: 0)
|
136
|
+
end
|
137
|
+
|
138
|
+
@pid = 0
|
139
|
+
@mtime = 0
|
140
|
+
|
141
|
+
main do
|
142
|
+
if file = params[:file]
|
143
|
+
loop do
|
144
|
+
@mtime = File.mtime file
|
145
|
+
@pid = spawn 'ruby', file
|
146
|
+
puts "##{$$} -> ##{@pid}"
|
147
|
+
loop do
|
148
|
+
sleep 5
|
149
|
+
break if File.mtime(file) != @mtime
|
150
|
+
end
|
151
|
+
system 'taskkill', '/F', '/PID', @pid.to_s
|
152
|
+
end
|
153
|
+
end
|
154
|
+
rescue Interrupt
|
155
|
+
system 'taskkill', '/F', '/PID', @pid.to_s
|
156
|
+
puts 'bye'
|
157
|
+
end<code></code></pre>
|
9
158
|
</body>
|
10
159
|
</html>
|
data/lib/lbq/cli/version.rb
CHANGED
data/lib/lbq/cli.rb
CHANGED
@@ -123,7 +123,9 @@ module Lbq
|
|
123
123
|
def load_script cmd, *argv
|
124
124
|
filename = File.expand_path "~/lbq/#{cmd}.rb"
|
125
125
|
script = <<~RUBY
|
126
|
-
|
126
|
+
# coding: utf-8
|
127
|
+
|
128
|
+
ARGV.clear.push *#{argv.map { |e| e.dup.encode('utf-8') }.inspect}
|
127
129
|
|
128
130
|
def arg2key arg
|
129
131
|
(arg.start_with?('--') ? arg[2..-1].tr('-', '_') : arg[1..-1]).to_sym
|
@@ -217,7 +219,7 @@ module Lbq
|
|
217
219
|
RUBY
|
218
220
|
eval <<~RUBY, TOPLEVEL_BINDING.dup, filename, -script.lines.size
|
219
221
|
#{script}
|
220
|
-
#{File.read filename}
|
222
|
+
#{File.read filename, encoding: 'utf-8'}
|
221
223
|
RUBY
|
222
224
|
end
|
223
225
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lbq-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hyrious
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|