1 // Copyright 2018-2019 Mozilla
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 // this file except in compliance with the License. You may obtain a copy of the
5 // License at http://www.apache.org/licenses/LICENSE-2.0
6 // Unless required by applicable law or agreed to in writing, software distributed
7 // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
8 // CONDITIONS OF ANY KIND, either express or implied. See the License for the
9 // specific language governing permissions and limitations under the License.
10
11 use std::{
12 env::args,
13 io,
14 path::Path,
15 };
16
17 use rkv::migrator::{
18 LmdbArchMigrateError,
19 LmdbArchMigrator,
20 };
21
main() -> Result<(), LmdbArchMigrateError>22 fn main() -> Result<(), LmdbArchMigrateError> {
23 let mut cli_args = args();
24 let mut db_name = None;
25 let mut env_path = None;
26
27 // The first arg is the name of the program, which we can ignore.
28 cli_args.next();
29
30 while let Some(arg) = cli_args.next() {
31 if &arg[0..1] == "-" {
32 match &arg[1..] {
33 "s" => {
34 db_name = match cli_args.next() {
35 None => return Err("-s must be followed by database name".into()),
36 Some(str) => Some(str),
37 };
38 },
39 str => return Err(format!("arg -{} not recognized", str).into()),
40 }
41 } else {
42 if env_path.is_some() {
43 return Err("must provide only one path to the LMDB environment".into());
44 }
45 env_path = Some(arg);
46 }
47 }
48
49 let env_path = env_path.ok_or("must provide a path to the LMDB environment")?;
50 let mut migrator = LmdbArchMigrator::new(Path::new(&env_path))?;
51 migrator.dump(db_name.as_deref(), io::stdout()).unwrap();
52
53 Ok(())
54 }
55