alain 0.5.0 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/alain +6 -5
- data/lib/alain/cargo.rb +16 -11
- data/lib/alain/driver.rb +13 -12
- data/lib/alain/proto.rb +1 -1
- data/lib/alain/templates/lib.rs.erb +4 -8
- data/lib/alain/templates/main.rs.erb +5 -2
- data/lib/alain/templates/mod.rs.erb +3 -5
- data/lib/alain/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4089b0af1f0afb99cd6dbde91e983980abbf5fd68f364adf7970632d05042b7d
|
4
|
+
data.tar.gz: d5ee7244a3cf0342e9530cb825063beb83e874549e562079ab42857225b1d754
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7836ebc4e29faf932a6e95d9c2b2f28ab730f08adcdd635e6246c2385a5a7fc7bc8353431916359fcd8d65ccd3040e0bfafef79ef0f749386b85a90db35b2912
|
7
|
+
data.tar.gz: 27696c2370f5864d6c6731c88a8defaa4f5ecde864bd7c77046b2ed6fe3f83fb1fa14bc94e4e381b002a6d4e3f4bdbd3549d0f7c7359f01e6188f231843dde80
|
data/exe/alain
CHANGED
@@ -7,7 +7,7 @@ require 'alain'
|
|
7
7
|
class AlainCmd
|
8
8
|
def self.generate(args, params)
|
9
9
|
if check_git || params[:force_overwrite]
|
10
|
-
Alain::Driver.new(args[0]).generate(params[:update_server])
|
10
|
+
Alain::Driver.new(args[0]).generate(params[:update_server], params[:server_conf])
|
11
11
|
else
|
12
12
|
exit 1
|
13
13
|
end
|
@@ -19,15 +19,15 @@ class AlainCmd
|
|
19
19
|
rescue
|
20
20
|
end
|
21
21
|
unless s == 0
|
22
|
-
puts "Requires git repository. If your sure, you can use '--force' option"
|
23
|
-
puts 'Exit'
|
22
|
+
STDERR.puts "Requires git repository. If your sure, you can use '--force' option"
|
23
|
+
STDERR.puts 'Exit'
|
24
24
|
return false
|
25
25
|
end
|
26
26
|
|
27
27
|
o, _, _ = Open3.capture3('git status -s | wc -l')
|
28
28
|
unless o.to_i == 0
|
29
|
-
puts "Commit working diffs before running. If your sure, you can use '--force' option."
|
30
|
-
puts 'Exit'
|
29
|
+
STDERR.puts "Commit working diffs before running. If your sure, you can use '--force' option."
|
30
|
+
STDERR.puts 'Exit'
|
31
31
|
return false
|
32
32
|
end
|
33
33
|
true
|
@@ -41,6 +41,7 @@ OptionParser.new do |opt|
|
|
41
41
|
opt.banner = 'Usage: alain [options] proto_file'
|
42
42
|
opt.on('--force', 'force generate files') { |_v| params[:force_overwrite] = true }
|
43
43
|
opt.on('--update-server', 'Overwrite main.rs/lib.rs with reference server') { |_v| params[:update_server] = true }
|
44
|
+
opt.on('--use-server-conf', 'introduce github.com/chumaltd/server-util') { |_v| params[:server_conf] = true }
|
44
45
|
args = opt.parse!(ARGV)
|
45
46
|
AlainCmd.generate(args, params)
|
46
47
|
end
|
data/lib/alain/cargo.rb
CHANGED
@@ -8,20 +8,20 @@ module Alain #:nodoc:
|
|
8
8
|
def initialize(dir = '.')
|
9
9
|
toml = Pathname(dir) / 'Cargo.toml'
|
10
10
|
unless File.exist? toml
|
11
|
-
puts "./Cargo.toml not found. 'cargo
|
11
|
+
STDERR.puts "./Cargo.toml not found. 'cargo init' first."
|
12
12
|
exit 1
|
13
13
|
end
|
14
14
|
@cargo = Tomlrb.load_file toml
|
15
15
|
end
|
16
16
|
|
17
|
-
def add_dependencies
|
17
|
+
def add_dependencies(server_conf: false)
|
18
18
|
toml = Pathname('.') / 'Cargo.toml'
|
19
19
|
origin = File.read toml
|
20
20
|
File.open(toml, 'w') do |f|
|
21
21
|
origin.each_line do |line|
|
22
22
|
if /^\[dependencies\]/.match(line)
|
23
23
|
f.puts line
|
24
|
-
dependencies.each do |k, entry|
|
24
|
+
dependencies(server_conf).each do |k, entry|
|
25
25
|
next if @cargo['dependencies'].keys.include? k
|
26
26
|
f.puts entry
|
27
27
|
end
|
@@ -48,23 +48,28 @@ module Alain #:nodoc:
|
|
48
48
|
|
49
49
|
private
|
50
50
|
|
51
|
-
def dependencies
|
51
|
+
def dependencies(server_conf)
|
52
52
|
{
|
53
|
-
'
|
54
|
-
'prost' => %(prost = "0.
|
55
|
-
'prost-types' => %(prost-types = "0.7"),
|
53
|
+
'prost' => %(prost = "0.10"),
|
54
|
+
'prost-types' => %(prost-types = "0.10"),
|
56
55
|
'signal-hook' => %(signal-hook = "0.3.9"),
|
57
56
|
'signal-hook-tokio' => %(signal-hook-tokio = { version = "0.3.0", features = ["futures-v0_3"] }),
|
58
57
|
'tokio' => %(tokio = { version = "1.0", features = ["full"] }),
|
59
58
|
'tokio-stream' => %(tokio-stream = "0.1.2"),
|
60
|
-
'tonic' => %(tonic = "0.
|
61
|
-
'triggered' => %(triggered = "0.1.
|
62
|
-
}
|
59
|
+
'tonic' => %(tonic = "0.7"),
|
60
|
+
'triggered' => %(triggered = "0.1.2")
|
61
|
+
}.tap do |dep|
|
62
|
+
if server_conf
|
63
|
+
dep['server-conf'] = %(server-conf = { git = "https://github.com/chumaltd/server-util.git" })
|
64
|
+
else
|
65
|
+
dep['once_cell'] = %(once_cell = "1.5")
|
66
|
+
end
|
67
|
+
end
|
63
68
|
end
|
64
69
|
|
65
70
|
def build_dependencies
|
66
71
|
{
|
67
|
-
'tonic-build' => %(tonic-build = { version = "0.
|
72
|
+
'tonic-build' => %(tonic-build = { version = "0.7", features = ["prost"] }),
|
68
73
|
}
|
69
74
|
end
|
70
75
|
end
|
data/lib/alain/driver.rb
CHANGED
@@ -16,32 +16,33 @@ module Alain #:nodoc:
|
|
16
16
|
@svc_code = SvcCode.new proto.service_name(:snake)
|
17
17
|
end
|
18
18
|
|
19
|
-
def generate(update_server = false)
|
19
|
+
def generate(update_server = false, server_conf = false)
|
20
|
+
@server_conf = server_conf
|
20
21
|
if @svc_code.exist?
|
21
|
-
puts 'Already exists service definition. Only update methods...'
|
22
|
+
STDERR.puts 'Already exists service definition. Only update methods...'
|
22
23
|
update_svc
|
23
24
|
else
|
24
25
|
update_server = true
|
25
|
-
puts 'No service definition yet...'
|
26
|
-
puts 'Generate service definition'
|
26
|
+
STDERR.puts 'No service definition yet...'
|
27
|
+
STDERR.puts 'Generate service definition'
|
27
28
|
parse_svc
|
28
29
|
end
|
29
30
|
if update_server
|
30
|
-
puts 'Overwrite main.rs'
|
31
|
+
STDERR.puts 'Overwrite main.rs'
|
31
32
|
parse_erb 'main.rs'
|
32
|
-
puts 'Overwrite lib.rs'
|
33
|
+
STDERR.puts 'Overwrite lib.rs'
|
33
34
|
parse_erb 'lib.rs'
|
34
|
-
puts 'Generate build.rs'
|
35
|
+
STDERR.puts 'Generate build.rs'
|
35
36
|
parse_erb 'build.rs', '', '.'
|
36
|
-
puts 'Generate tests/common/mod.rs'
|
37
|
+
STDERR.puts 'Generate tests/common/mod.rs'
|
37
38
|
FileUtils.mkdir_p 'tests/common/'
|
38
39
|
parse_erb 'mod.rs', '', 'tests/common'
|
39
|
-
puts 'Generate tests/integration_test.rs'
|
40
|
+
STDERR.puts 'Generate tests/integration_test.rs'
|
40
41
|
parse_erb 'integration_test.rs', '', 'tests'
|
41
|
-
puts 'Update Cargo.toml'
|
42
|
-
cargo.add_dependencies
|
42
|
+
STDERR.puts 'Update Cargo.toml'
|
43
|
+
cargo.add_dependencies(server_conf: @server_conf)
|
43
44
|
end
|
44
|
-
puts 'Done'
|
45
|
+
STDERR.puts 'Done'
|
45
46
|
end
|
46
47
|
|
47
48
|
private
|
data/lib/alain/proto.rb
CHANGED
@@ -13,17 +13,13 @@ mod <%= proto.service_name :snake %>_service;
|
|
13
13
|
use self::<%= proto.service_name :snake %>_service::<%= proto.service_name %>Service;
|
14
14
|
|
15
15
|
pub async fn start_server(addr: SocketAddr, signal: Listener) -> Result<(), Box<dyn std::error::Error>> {
|
16
|
-
println!("ready");
|
17
|
-
create_router().await
|
18
|
-
.serve_with_shutdown(addr, signal).await.unwrap();
|
19
|
-
|
20
|
-
Ok(())
|
21
|
-
}
|
22
|
-
|
23
|
-
pub async fn create_router() -> Router<<%= proto.service_name %>Server<<%= proto.service_name %>Service>, tonic::transport::server::Unimplemented> {
|
24
16
|
let server = <%= proto.service_name %>Service{};
|
17
|
+
println!("{} {} ready, Listen {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"), addr);
|
25
18
|
Server::builder()
|
26
19
|
.add_service(<%= proto.service_name %>Server::new(server))
|
20
|
+
.serve_with_shutdown(addr, signal).await.unwrap();
|
21
|
+
|
22
|
+
Ok(())
|
27
23
|
}
|
28
24
|
|
29
25
|
pub async fn handle_signals(signals: Signals, trigger: triggered::Trigger) {
|
@@ -1,12 +1,15 @@
|
|
1
|
-
use once_cell::sync::Lazy;
|
2
1
|
use signal_hook::consts::signal::*;
|
3
2
|
use signal_hook_tokio::Signals;
|
4
3
|
use <%= cargo.crate_name %>::{start_server, handle_signals};
|
5
|
-
|
4
|
+
<% if @server_conf -%>
|
5
|
+
use server_conf::SERVER_BIND;
|
6
|
+
<% else -%>
|
7
|
+
use once_cell::sync::Lazy;
|
6
8
|
pub static SERVER_BIND: Lazy<std::net::SocketAddr> = Lazy::new(|| {
|
7
9
|
format!("{}:{}", "0.0.0.0", 50051)
|
8
10
|
.parse().unwrap()
|
9
11
|
});
|
12
|
+
<% end -%>
|
10
13
|
|
11
14
|
#[tokio::main]
|
12
15
|
pub async fn main() {
|
@@ -3,14 +3,13 @@ use std::time::Duration;
|
|
3
3
|
use tokio::task::JoinHandle;
|
4
4
|
use tonic::{transport::Channel, Status};
|
5
5
|
use triggered::{trigger, Trigger};
|
6
|
-
use <%= cargo.crate_name %>::
|
6
|
+
use <%= cargo.crate_name %>::start_server;
|
7
7
|
|
8
8
|
pub async fn setup() -> Result<(JoinHandle<()>, Channel, Trigger), Box<dyn std::error::Error>> {
|
9
9
|
let (shutdown_trigger, signal) = trigger();
|
10
10
|
let srv: JoinHandle<()> = tokio::spawn(async move {
|
11
11
|
// Launch gRPC server
|
12
|
-
|
13
|
-
.serve_with_shutdown("127.0.0.1:50051".parse().unwrap(), signal)
|
12
|
+
start_server("127.0.0.1:50051".parse().unwrap(), signal)
|
14
13
|
.await.unwrap()
|
15
14
|
});
|
16
15
|
|
@@ -20,8 +19,7 @@ pub async fn setup() -> Result<(JoinHandle<()>, Channel, Trigger), Box<dyn std::
|
|
20
19
|
let channel = Channel::from_static("http://127.0.0.1:50051")
|
21
20
|
.timeout(Duration::from_secs(30))
|
22
21
|
.concurrency_limit(20)
|
23
|
-
.connect_lazy()
|
24
|
-
.or_else(|_e| Err(Status::cancelled("client connection error")))?;
|
22
|
+
.connect_lazy();
|
25
23
|
|
26
24
|
Ok((srv, channel, shutdown_trigger))
|
27
25
|
}
|
data/lib/alain/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chuma Takahiro
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tomlrb
|
@@ -53,7 +53,7 @@ metadata:
|
|
53
53
|
homepage_uri: https://github.com/chumaltd/alain
|
54
54
|
source_code_uri: https://github.com/chumaltd/alain
|
55
55
|
changelog_uri: https://github.com/chumaltd/alain/blob/main/CHANGELOG.md
|
56
|
-
post_install_message:
|
56
|
+
post_install_message:
|
57
57
|
rdoc_options: []
|
58
58
|
require_paths:
|
59
59
|
- lib
|
@@ -68,8 +68,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
70
|
requirements: []
|
71
|
-
rubygems_version: 3.
|
72
|
-
signing_key:
|
71
|
+
rubygems_version: 3.3.5
|
72
|
+
signing_key:
|
73
73
|
specification_version: 4
|
74
74
|
summary: Code generator for rust prost
|
75
75
|
test_files: []
|