diff --git a/src/cmd/create/command.rs b/src/cmd/create/command.rs new file mode 100644 index 0000000..cb23e19 --- /dev/null +++ b/src/cmd/create/command.rs @@ -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, + 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(()) +} diff --git a/src/cmd/create/mod.rs b/src/cmd/create/mod.rs new file mode 100644 index 0000000..be20e29 --- /dev/null +++ b/src/cmd/create/mod.rs @@ -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; diff --git a/src/cmd/create/parse.rs b/src/cmd/create/parse.rs new file mode 100644 index 0000000..2c5bfd4 --- /dev/null +++ b/src/cmd/create/parse.rs @@ -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 { + 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 { + 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()); + } + } +} diff --git a/util/src/fat.rs b/util/src/fat.rs new file mode 100644 index 0000000..0ee1370 --- /dev/null +++ b/util/src/fat.rs @@ -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