Skip to content
This repository was archived by the owner on Dec 15, 2023. It is now read-only.

Commit 3f15089

Browse files
committed
fix: sun cmd session bug
1 parent 2b739e5 commit 3f15089

File tree

5 files changed

+37
-23
lines changed

5 files changed

+37
-23
lines changed

.github/workflows/cargo_fmt.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ jobs:
1414
- name: Install Rust
1515
run: rustup update stable && rustup default stable && rustup component add rustfmt
1616
- run: |
17+
cargo fmt --all
1718
cargo fmt -- --check
1819
cargo clippy

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "iotdb-cli"
3-
version = "0.0.2"
3+
version = "0.0.3-alpha"
44
edition = "2021"
55
license = "Apache-2.0"
66
readme = "README.md"

src/cmd.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,33 +58,33 @@ pub fn run() {
5858
std::process::exit(0);
5959
}
6060

61-
// open session
62-
let prompt = format!("IOTDB#({})> ", conf.endpoint.to_string());
63-
let mut session = open_session(conf.clone());
64-
65-
// sub command
61+
// No session sub command
6662
match sub_cmd {
6763
None => {
64+
// open session
65+
let prompt = format!("IOTDB#({})> ", conf.endpoint.to_string());
66+
let mut session = open_session(conf);
67+
6868
if let Some(sql) = sql {
6969
session.sql(sql.as_str()).unwrap().show()
7070
} else {
7171
readline(session, prompt)
7272
}
7373
}
74-
Some(sub_cmd) => match sub_cmd {
75-
// exec batch
76-
SubCmd::File { file_path } => {
77-
if let Some(file_path) = file_path {
78-
exec_batch_from_file(conf, &file_path);
74+
Some(sub_cmd) => {
75+
match sub_cmd {
76+
// exec sql form file
77+
SubCmd::File { file_path } => {
78+
if let Some(file_path) = file_path {
79+
exec_batch_from_file(conf, &file_path);
80+
}
7981
}
82+
SubCmd::Usage => print_usage_info(),
83+
SubCmd::Update => update(),
84+
SubCmd::Csv { .. } => {}
85+
SubCmd::Load => {}
8086
}
81-
SubCmd::Usage => {
82-
print_usage_info();
83-
}
84-
SubCmd::Update => {
85-
update();
86-
}
87-
},
87+
}
8888
}
8989
}
9090

@@ -100,7 +100,7 @@ fn readline(mut session: Session, prompt: String) {
100100
"{}\nAuthor: {}\nVersion: {} v{}\nUsage:\n{}\
101101
1. Print usage info: `?` or `help` \n{}\
102102
2. Exec system command on OS: `!ps`\n{}\
103-
3. Exit: `exit` or `quit` or `Ctrl-C` or `Ctrl-D`",
103+
3. Exit: `exit` or `quit` or `Ctrl-C` or `Ctrl-D`\n",
104104
ASCII_NAME, AUTHORS, PKG_NAME, VERSION, fore_space, fore_space, fore_space
105105
);
106106
let his_file: PathBuf = dirs::home_dir()
@@ -158,7 +158,7 @@ fn readline(mut session: Session, prompt: String) {
158158
}
159159
} else {
160160
sql = format!("{}{}", tmp_sql, sql);
161-
println!("```sql\n{}\n```", sql);
161+
println!("```\n{}\n```", sql);
162162
if let Ok(mut ds) = session.sql(sql.as_str()) {
163163
ds.show()
164164
}

src/opt.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{ASCII_NAME, AUTHORS, PKG_NAME};
22
use structopt::StructOpt;
33

4-
#[derive(StructOpt, Debug)]
4+
#[derive(Debug, Clone, StructOpt)]
55
#[structopt(name = format ! ("{}\nAuthor: {}\nVersion: {}", ASCII_NAME, AUTHORS, PKG_NAME))]
66
pub struct Cli {
77
/// Execute single sql, eg: `iotdb "show storage group"`
@@ -44,11 +44,23 @@ pub struct Cli {
4444
pub sub_cmd: Option<SubCmd>,
4545
}
4646

47-
#[derive(Debug, StructOpt)]
47+
#[derive(Debug, Clone, StructOpt)]
4848
pub enum SubCmd {
4949
/// Execute batch form sql file, eg: `iotdb file ddl.sql`
5050
File { file_path: Option<String> },
5151

52+
/// Csv util(TODO)
53+
Csv {
54+
#[structopt(short, long)]
55+
import: Option<String>,
56+
57+
#[structopt(short, long)]
58+
export: Option<String>,
59+
},
60+
61+
/// Load TsFile util(TODO)
62+
Load,
63+
5264
/// Print usage info
5365
Usage,
5466

src/sub_cmd.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::VERSION;
12
use std::fs;
23
use std::io;
34
use std::io::BufRead;
@@ -40,7 +41,7 @@ pub fn sql_file_reader(file_path: &str) -> Vec<String> {
4041

4142
#[allow(dead_code)]
4243
pub fn update() {
43-
todo!()
44+
println!("Update to {:?}", VERSION)
4445
}
4546

4647
#[allow(dead_code)]

0 commit comments

Comments
 (0)