1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
use Parser;
use ;
use ;
use AppError;
// fn cp_json_path(
// source: &str,
// json_path: &str,
// target_json_path: &Vec<String>,
// base_path: &Option<String>,
// ) -> Result<(), Box<dyn std::error::Error>> {
// let base_path = base_path.clone().unwrap_or_default();
// let source_path = Path::new(&base_path).join(source);
//
// {
// let mut cmd = Cli::command();
// let tmp_path = path_to_normalized_str(&source_path).unwrap();
// if !source_path.exists() {
// cmd.error(
// ErrorKind::InvalidValue,
// format!("source path not exists, source path: {}", tmp_path),
// )
// .exit();
// }
// if !source_path.is_file() {
// cmd.error(
// ErrorKind::InvalidValue,
// format!("source path is not a file, source path: {}", tmp_path),
// )
// .exit();
// }
// if source_path.extension().unwrap().ne("json") {
// cmd.error(
// ErrorKind::InvalidValue,
// format!("source path is not a json file, source path: {}", tmp_path),
// )
// .exit()
// }
// }
//
// let source_content = fs::read_to_string(source_path)?;
// // *json 默认是无序的,如果想要保持顺序那么就需要为 serde_json 添加 preserve_order 这个 features
// let source_json: Value = serde_json::from_str(&source_content)?;
//
// for str in target_json_path {
// let target_path = Path::new(&base_path).join(str);
// let target_path_str = path_to_normalized_str(&target_path).unwrap();
//
// {
// let mut cmd = Cli::command();
// if !target_path.exists() {
// cmd.error(
// ErrorKind::InvalidValue,
// format!("source path not exists, source path: {}", target_path_str),
// )
// .exit();
// }
// if !target_path.is_file() {
// cmd.error(
// ErrorKind::InvalidValue,
// format!(
// "source path is not a file, source path: {}",
// target_path_str
// ),
// )
// .exit();
// }
// if target_path.extension().unwrap().ne("json") {
// cmd.error(
// ErrorKind::InvalidValue,
// format!(
// "source path is not a json file, source path: {}",
// target_path_str
// ),
// )
// .exit();
// }
// }
//
// let target_content = fs::read_to_string(&target_path)?;
// let target_json: Value = serde_json::from_str(&target_content)?;
//
// let ret: Value = replace_with(json_path, target_json, &mut |json_pointer, _| {
// source_json.pointer(json_pointer).cloned()
// })?;
//
// let json_result = serde_json::to_string_pretty(&ret)?;
//
// fs::write(&target_path, json_result).map(|_| {
// info!("target_path: {} is finished!", target_path_str);
// })?;
// }
//
// Ok(())
// }