Skip to content

Commit

Permalink
Implemented version querying
Browse files Browse the repository at this point in the history
  • Loading branch information
IHateYourCode committed Oct 9, 2022
1 parent 3610d17 commit e847e2c
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 1 deletion.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
# GCC

<br>

<div align = center>

# GCC

***[Deno]*** *module for **[GCC]**.*

<br>
<br>


</div>

<br>


<!----------------------------------------------------------------------------->

[Deno]: https://deno.land/
[GCC]: https://gcc.gnu.org/
20 changes: 20 additions & 0 deletions Source/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

## GCC

*Wrapper for the **[GCC]** command line interface.*

<br>
<br>

```js
import { version } from 'https://deno.land/x/gcc/mod.ts'

console.log('GCC Version:',await version());
```

<br>


<!----------------------------------------------------------------------------->

[GCC]: https://gcc.gnu.org/
57 changes: 57 additions & 0 deletions Source/Run.js
Original file line number Diff line number Diff line change
@@ -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
}
}
29 changes: 29 additions & 0 deletions Source/mod.ts
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit e847e2c

Please sign in to comment.