-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor create command into a subcommand, to allow for other types o…
…f creations
- Loading branch information
1 parent
818218c
commit 0a9a032
Showing
4 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2020 Revcore Technologies Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use crate::Error; | ||
use proj::{AloeVeraProject, Jsonable}; | ||
|
||
/// Arguments for the initial create project command | ||
pub struct CreateProjectArgs { | ||
pub id: Option<String>, | ||
pub output_file: String, | ||
} | ||
|
||
pub fn create_project(args: &CreateProjectArgs) -> Result<(), Error> { | ||
let id = match &args.id { | ||
Some(l) => l, | ||
None => "My Project", | ||
}; | ||
info!("Creating new project file at: {}", args.output_file); | ||
|
||
let proj = AloeVeraProject::new(id); | ||
let json = proj.to_json()?; | ||
crate::cmd::common::output_to_file(&args.output_file, &json.as_bytes())?; | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Arguments for the initial create project command | ||
pub struct CreateSDImageArgs { | ||
pub output_file: String, | ||
} | ||
|
||
pub fn create_sd_image(args: &CreateSDImageArgs) -> Result<(), Error> { | ||
info!( | ||
"Creating new SDCard (FAT32 FS) image at: {}", | ||
args.output_file | ||
); | ||
|
||
/*let proj = AloeVeraProject::new(id); | ||
let json = proj.to_json()?;*/ | ||
//crate::cmd::common::output_to_file(&args.output_file, &json.as_bytes())?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2020 Revcore Technologies Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
pub mod command; | ||
pub mod parse; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2020 Revcore Technologies Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
use super::command::{self, CreateProjectArgs, CreateSDImageArgs}; | ||
use crate::cmd::common; | ||
use crate::{Error, ErrorKind}; | ||
use clap::ArgMatches; | ||
|
||
pub fn parse_create_project_args(args: &ArgMatches) -> Result<CreateProjectArgs, Error> { | ||
let output_file = common::parse_required(args, "output_file")?; | ||
Ok(CreateProjectArgs { | ||
id: args.value_of("id").map(|s| s.into()), | ||
output_file: output_file.into(), | ||
}) | ||
} | ||
|
||
pub fn parse_create_sd_image_args(args: &ArgMatches) -> Result<CreateSDImageArgs, Error> { | ||
let output_file = common::parse_required(args, "output_file")?; | ||
Ok(CreateSDImageArgs { | ||
output_file: output_file.into(), | ||
}) | ||
} | ||
|
||
pub fn execute_create_command(args: &ArgMatches) -> Result<(), Error> { | ||
match args.subcommand() { | ||
("project", Some(args)) => { | ||
let a = arg_parse!(parse_create_project_args(args)); | ||
command::create_project(&a) | ||
} | ||
("sdimage", Some(args)) => { | ||
let a = arg_parse!(parse_create_sd_image_args(args)); | ||
command::create_sd_image(&a) | ||
} | ||
_ => { | ||
let msg = format!("Unknown sub command, use 'aloevera create --help' for details"); | ||
return Err(ErrorKind::ArgumentError(msg).into()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2020 Revcore Technologies Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//! Utilities to write to FAT Filesystem images, for eventual | ||
//! transfer to SD Cards |