]> git.proxmox.com Git - proxmox-backup.git/commitdiff
src/cli/command.rs: move doc generator code to src/api_schema/format.rs
authorDietmar Maurer <dietmar@proxmox.com>
Tue, 4 Jun 2019 06:24:50 +0000 (08:24 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 4 Jun 2019 10:32:22 +0000 (12:32 +0200)
src/api2/admin/datastore.rs
src/api2/admin/datastore/backup.rs
src/api_schema.rs
src/api_schema/format.rs [new file with mode: 0644]
src/cli/command.rs

index 7471a847db3b1844bd956a257a2eb8434b26f147..f55b1974b64655a8c3e93b67842c8550df0f1af3 100644 (file)
@@ -20,7 +20,7 @@ use crate::server::WorkerTask;
 
 mod pxar;
 mod upload;
-mod backup;
+pub mod backup;
 
 fn group_backups(backup_list: Vec<BackupInfo>) -> HashMap<String, Vec<BackupInfo>> {
 
index 4e5e701ae3294ca245314064a3bb77722a1d0eb6..a9380457ca12dab55792567220c48a08213bc845 100644 (file)
@@ -147,7 +147,7 @@ fn upgrade_to_backup_protocol(
     Ok(Box::new(futures::future::ok(response)))
 }
 
-fn backup_api() -> Router {
+pub fn backup_api() -> Router {
 
     let router = Router::new()
         .subdir(
index 27156df3a8591d1f027fb7e7e5224654dc8ea723..c41af58bd3384dccd97c418c48c2a29a1fb8349c 100644 (file)
@@ -17,3 +17,4 @@ pub mod registry;
 #[macro_use]
 pub mod router;
 pub mod config;
+pub mod format;
diff --git a/src/api_schema/format.rs b/src/api_schema/format.rs
new file mode 100644 (file)
index 0000000..b475cb4
--- /dev/null
@@ -0,0 +1,113 @@
+use crate::api_schema::*;
+
+#[derive(Copy, Clone)]
+pub enum ParameterDisplayStyle {
+    Config,
+    //SonfigSub,
+    Arg,
+    Fixed,
+}
+
+/// CLI usage information format
+#[derive(Copy, Clone, PartialEq)]
+pub enum DocumentationFormat {
+    /// text, command line only (one line)
+    Short,
+    /// text, list all options
+    Long,
+    /// text, include description
+    Full,
+    /// like full, but in reStructuredText format
+    ReST,
+}
+
+pub fn get_schema_type_text(schema: &Schema, _style: ParameterDisplayStyle) -> String {
+
+    let type_text = match schema {
+        Schema::Null => String::from("<null>"), // should not happen
+        Schema::String(_) => String::from("<string>"),
+        Schema::Boolean(_) => String::from("<boolean>"),
+        Schema::Integer(integer_schema) => {
+           match (integer_schema.minimum, integer_schema.maximum) {
+               (Some(min), Some(max)) => format!("<integer> ({} - {})", min, max),
+               (Some(min), None) => format!("<integer> ({} - N)", min),
+               (None, Some(max)) => format!("<integer> (-N - {})", max),
+               _ => String::from("<integer>"),
+           }
+       },
+        Schema::Object(_) => String::from("<object>"),
+        Schema::Array(_) => String::from("<array>"),
+    };
+
+    type_text
+}
+
+pub fn get_property_description(
+    name: &str,
+    schema: &Schema,
+    style: ParameterDisplayStyle,
+    format: DocumentationFormat,
+) -> String {
+
+    let type_text = get_schema_type_text(schema, style);
+
+    let (descr, default) = match schema {
+        Schema::Null => ("null", None),
+        Schema::String(ref schema) => (schema.description, schema.default.map(|v| v.to_owned())),
+        Schema::Boolean(ref schema) => (schema.description, schema.default.map(|v| v.to_string())),
+        Schema::Integer(ref schema) => (schema.description, schema.default.map(|v| v.to_string())),
+        Schema::Object(ref schema) => (schema.description, None),
+        Schema::Array(ref schema) => (schema.description, None),
+    };
+
+    let default_text = match default {
+        Some(text) =>  format!("   (default={})", text),
+        None => String::new(),
+    };
+
+    if format == DocumentationFormat::ReST {
+
+        let mut text = match style {
+            ParameterDisplayStyle::Config => {
+                format!(":``{} {}{}``:  ", name, type_text, default_text)
+            }
+            ParameterDisplayStyle::Arg => {
+                format!(":``--{} {}{}``:  ", name, type_text, default_text)
+            }
+            ParameterDisplayStyle::Fixed => {
+                format!(":``<{}> {}{}``:  ", name, type_text, default_text)
+            }
+        };
+
+        text.push_str(descr);
+        text.push('\n');
+        text.push('\n');
+
+        text
+
+    } else {
+
+        let display_name = match style {
+            ParameterDisplayStyle::Config => {
+                format!("{}:", name)
+            }
+            ParameterDisplayStyle::Arg => {
+                format!("--{}", name)
+            }
+            ParameterDisplayStyle::Fixed => {
+                format!("<{}>", name)
+            }
+        };
+
+        // fixme: wrap text
+        let mut text = format!(" {:-10} {}{}", display_name, type_text, default_text);
+        let indent = "             ";
+        text.push('\n');
+        text.push_str(indent);
+        text.push_str(descr);
+        text.push('\n');
+        text.push('\n');
+
+        text
+    }
+}
index 57c8fa8e42c933e53e44104040665dd9cbc2a2b2..7c472b3a9c53e3ae72b8076cb38e8ebdf23020ed 100644 (file)
@@ -4,116 +4,12 @@ use std::collections::HashSet;
 
 use crate::api_schema::*;
 use crate::api_schema::router::*;
+use crate::api_schema::format::*;
 //use crate::api_schema::config::*;
 use super::environment::CliEnvironment;
 
 use super::getopts;
 
-#[derive(Copy, Clone)]
-enum ParameterDisplayStyle {
-    //Config,
-    //SonfigSub,
-    Arg,
-    Fixed,
-}
-
-/// CLI usage information format
-#[derive(Copy, Clone, PartialEq)]
-enum DocumentationFormat {
-    /// text, command line only (one line)
-    Short,
-    /// text, list all options
-    Long,
-    /// text, include description
-    Full,
-    /// like full, but in reStructuredText format
-    ReST,
-}
-
-fn get_schema_type_text(schema: &Schema, _style: ParameterDisplayStyle) -> String {
-
-    let type_text = match schema {
-        Schema::Null => String::from("<null>"), // should not happen
-        Schema::String(_) => String::from("<string>"),
-        Schema::Boolean(_) => String::from("<boolean>"),
-        Schema::Integer(integer_schema) => {
-           match (integer_schema.minimum, integer_schema.maximum) {
-               (Some(min), Some(max)) => format!("<integer> ({} - {})", min, max),
-               (Some(min), None) => format!("<integer> ({} - N)", min),
-               (None, Some(max)) => format!("<integer> (-N - {})", max),
-               _ => String::from("<integer>"),
-           }
-       },
-        Schema::Object(_) => String::from("<object>"),
-        Schema::Array(_) => String::from("<array>"),
-    };
-
-    type_text
-}
-
-fn get_property_description(
-    name: &str,
-    schema: &Schema,
-    style: ParameterDisplayStyle,
-    format: DocumentationFormat,
-) -> String {
-
-    let type_text = get_schema_type_text(schema, style);
-
-    let (descr, default) = match schema {
-        Schema::Null => ("null", None),
-        Schema::String(ref schema) => (schema.description, schema.default.map(|v| v.to_owned())),
-        Schema::Boolean(ref schema) => (schema.description, schema.default.map(|v| v.to_string())),
-        Schema::Integer(ref schema) => (schema.description, schema.default.map(|v| v.to_string())),
-        Schema::Object(ref schema) => (schema.description, None),
-        Schema::Array(ref schema) => (schema.description, None),
-    };
-
-    let default_text = match default {
-        Some(text) =>  format!("   (default={})", text),
-        None => String::new(),
-    };
-
-    if format == DocumentationFormat::ReST {
-
-        let mut text = match style {
-           ParameterDisplayStyle::Arg => {
-                format!(":``--{} {}{}``:  ", name, type_text, default_text)
-            }
-            ParameterDisplayStyle::Fixed => {
-                format!(":``<{}> {}{}``:  ", name, type_text, default_text)
-            }
-        };
-
-        text.push_str(descr);
-        text.push('\n');
-        text.push('\n');
-
-        text
-
-    } else {
-
-        let display_name = match style {
-            ParameterDisplayStyle::Arg => {
-                format!("--{}", name)
-            }
-            ParameterDisplayStyle::Fixed => {
-                format!("<{}>", name)
-            }
-        };
-
-        // fixme: wrap text
-        let mut text = format!(" {:-10} {}{}", display_name, type_text, default_text);
-        let indent = "             ";
-        text.push('\n');
-        text.push_str(indent);
-        text.push_str(descr);
-        text.push('\n');
-        text.push('\n');
-
-        text
-    }
-}
 
 fn generate_usage_str(
     prefix: &str,