From 186fa7f0d44949cad9df7e7b3a28b7529be533ce Mon Sep 17 00:00:00 2001
From: Xavier L'Heureux <xavier.lheureux@icloud.com>
Date: Tue, 25 Jun 2019 15:38:24 -0400
Subject: [PATCH] Document the calc builtin and deny non-documented public
 structs

---
 src/lib/builtins/calc.rs | 65 +++++++++++++++++++---------------------
 src/lib/builtins/mod.rs  |  9 +-----
 src/lib/lib.rs           |  2 +-
 3 files changed, 32 insertions(+), 44 deletions(-)

diff --git a/src/lib/builtins/calc.rs b/src/lib/builtins/calc.rs
index 3c545ee3..2008b008 100644
--- a/src/lib/builtins/calc.rs
+++ b/src/lib/builtins/calc.rs
@@ -1,14 +1,23 @@
+use super::Status;
+use crate as ion_shell;
+use builtins_proc::builtin;
 use calc::{eval, eval_polish, CalcError, Value};
-use small;
 use std::io::{self, Write};
 
 const REPL_GUIDE: &str = r#"ion-calc
 Type in expressions to have them evaluated.
 Type "help" for help."#;
 
-pub const MAN_CALC: &str = r#"NAME
-    calc - Floating point calculator
+fn calc_or_polish_calc(args: &str) -> Result<Value, CalcError> {
+    match eval(&args) {
+        Ok(t) => Ok(t),
+        Err(_) => eval_polish(&args),
+    }
+}
 
+#[builtin(
+    desc = "Floating-point calculator",
+    man = "
 SYNOPSIS
     calc [EXPRESSION]
 
@@ -40,33 +49,21 @@ EXAMPLES
         calc + 2 2
 
 AUTHOR
-    Written by Hunter Goldstein.
-"#;
-
-fn calc_or_polish_calc(args: &str) -> Result<Value, CalcError> {
-    match eval(&args) {
-        Ok(t) => Ok(t),
-        Err(_) => eval_polish(&args),
-    }
-}
-
-pub fn calc(args: &[small::String]) -> Result<(), String> {
+    Written by Hunter Goldstein."
+)]
+pub fn calc(args: &[crate::types::Str], _: &mut crate::Shell<'_>) -> Status {
     let stdout = io::stdout();
     let mut stdout = stdout.lock();
-    match args.first() {
-        Some(ref s) if (*s == "--help") => {
-            // "--help" only makes sense if it is the first option. Only look for it
-            // in the first position.
-            println!("{}", MAN_CALC);
-            Ok(())
-        }
+    match args.get(1) {
         Some(_) => {
-            let result = calc_or_polish_calc(&args.join(" "));
-            let _ = match result {
-                Ok(v) => writeln!(stdout, "{}", v),
-                Err(e) => writeln!(stdout, "{}", e),
-            };
-            Ok(())
+            let result = calc_or_polish_calc(&args[1..].join(" "));
+            match result {
+                Ok(v) => {
+                    println!("{}", v);
+                    Status::SUCCESS
+                }
+                Err(e) => Status::error(format!("{}", e)),
+            }
         }
         None => {
             let prompt = b"ion-calc: ";
@@ -77,23 +74,21 @@ pub fn calc(args: &[small::String]) -> Result<(), String> {
                 let mut input = String::new();
                 let _ = io::stdin().read_line(&mut input);
                 if input.is_empty() {
-                    break;
+                    return Status::SUCCESS;
                 } else {
                     match input.trim() {
                         "" => (),
-                        "exit" => break,
-                        "help" => println!("{}", MAN_CALC),
+                        "exit" => return Status::SUCCESS,
                         s => {
                             let result = calc_or_polish_calc(s);
-                            let _ = match result {
-                                Ok(v) => writeln!(stdout, "{}", v),
-                                Err(e) => writeln!(stdout, "{}", e),
-                            };
+                            match result {
+                                Ok(v) => println!("{}", v),
+                                Err(e) => eprintln!("{}", e),
+                            }
                         }
                     }
                 }
             }
-            Ok(())
         }
     }
 }
diff --git a/src/lib/builtins/mod.rs b/src/lib/builtins/mod.rs
index d796f242..309e9c24 100644
--- a/src/lib/builtins/mod.rs
+++ b/src/lib/builtins/mod.rs
@@ -18,6 +18,7 @@ mod test;
 mod variables;
 
 pub use self::{
+    calc::builtin_calc,
     command_info::builtin_which,
     conditionals::{builtin_contains, builtin_ends_with, builtin_starts_with},
     echo::builtin_echo,
@@ -619,14 +620,6 @@ pub fn eval(args: &[types::Str], shell: &mut Shell<'_>) -> Status {
     })
 }
 
-// TODO create manpage.
-pub fn builtin_calc(args: &[types::Str], _: &mut Shell<'_>) -> Status {
-    match calc::calc(&args[1..]) {
-        Ok(()) => Status::SUCCESS,
-        Err(why) => Status::error(why),
-    }
-}
-
 #[builtin(
     desc = "generate a random number",
     man = "
diff --git a/src/lib/lib.rs b/src/lib/lib.rs
index 6c3e16f3..30c2d41e 100644
--- a/src/lib/lib.rs
+++ b/src/lib/lib.rs
@@ -60,7 +60,7 @@
 //! ```
 
 #![allow(unknown_lints)]
-#![warn(missing_docs)]
+#![deny(missing_docs)]
 use ion_ranges as ranges;
 
 /// The various types used for storing values
-- 
GitLab