From e847e2cdc74186477c7ac959e6697dbb80e1a42a Mon Sep 17 00:00:00 2001
From: IHateYourCode <89636625+IHateYourCode@users.noreply.github.com>
Date: Sun, 9 Oct 2022 03:44:50 -0400
Subject: [PATCH] Implemented version querying
---
README.md | 23 ++++++++++++++++++-
Source/README.md | 20 +++++++++++++++++
Source/Run.js | 57 ++++++++++++++++++++++++++++++++++++++++++++++++
Source/mod.ts | 29 ++++++++++++++++++++++++
4 files changed, 128 insertions(+), 1 deletion(-)
create mode 100644 Source/README.md
create mode 100644 Source/Run.js
create mode 100644 Source/mod.ts
diff --git a/README.md b/README.md
index b9c66da..84aa3a7 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,22 @@
-# GCC
\ No newline at end of file
+
+
+
+
+
+# GCC
+
+***[Deno]*** *module for **[GCC]**.*
+
+
+
+
+
+
+
+
+
+
+
+
+[Deno]: https://deno.land/
+[GCC]: https://gcc.gnu.org/
\ No newline at end of file
diff --git a/Source/README.md b/Source/README.md
new file mode 100644
index 0000000..4811b36
--- /dev/null
+++ b/Source/README.md
@@ -0,0 +1,20 @@
+
+## GCC
+
+*Wrapper for the **[GCC]** command line interface.*
+
+
+
+
+```js
+import { version } from 'https://deno.land/x/gcc/mod.ts'
+
+console.log('GCC Version:',await version());
+```
+
+
+
+
+
+
+[GCC]: https://gcc.gnu.org/
\ No newline at end of file
diff --git a/Source/Run.js b/Source/Run.js
new file mode 100644
index 0000000..bcbeedc
--- /dev/null
+++ b/Source/Run.js
@@ -0,0 +1,57 @@
+
+const { errors , run } = Deno;
+const { NotFound } = errors;
+
+
+export default async function ( options ){
+
+ const {
+ workingDirectory = null ,
+ returnErrors = false ,
+ returnOutput = false ,
+ parameters = []
+ } = options;
+
+ try {
+
+ const config = {
+ stdout : 'null' ,
+ stderr : 'null' ,
+ cwd : workingDirectory ,
+ cmd : [ 'gcc' , ... parameters ]
+ }
+
+ if(returnErrors)
+ config.stderr = 'piped';
+
+ if(returnOutput)
+ config.stdout = 'piped';
+
+ const process = await run(config);
+
+
+ const { success , code } = await process.status();
+
+ if(!success)
+ throw new Error(`GCC encountered a fatal error. Code: ${ code }`);
+
+ const data = {}
+
+ if(returnErrors)
+ data.errors = new TextDecoder()
+ .decode(await process.stderrOutput());
+
+ if(returnOutput)
+ data.output = new TextDecoder()
+ .decode(await process.output());
+
+ return data;
+
+ } catch ( error ) {
+
+ if(error instanceof NotFound)
+ error = new NotFound('GCC executable is missing.');
+
+ throw error
+ }
+}
\ No newline at end of file
diff --git a/Source/mod.ts b/Source/mod.ts
new file mode 100644
index 0000000..36c4876
--- /dev/null
+++ b/Source/mod.ts
@@ -0,0 +1,29 @@
+
+import run from './Run.js'
+
+
+/**
+ * @brief Return the gcc version string
+ * which includes the system version.
+ */
+
+export async function versionString (){
+
+ const { output } = await run ({
+ parameters : [ '--version' ] ,
+ returnOutput : true ,
+ })
+
+ return output.split('\n')[0];
+}
+
+
+/**
+ * @brief Return the gcc version.
+ */
+
+export async function version (){
+ return (await versionString())
+ .split(' ')
+ .pop();
+}
\ No newline at end of file