Skip to content

Commit

Permalink
add commander parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
younthu committed Apr 21, 2024
1 parent e3ff4fb commit 600b9b8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
31 changes: 18 additions & 13 deletions bin/command.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#! /usr/bin/env node
import { NugetDepsTree } from '../src';
import { NugetDepsTree, Project, DependencyTree } from '../src';
const { program } = require('commander');

const args = process.argv.slice(2);
if (args.length !== 1) {
throw new Error("Wrong number of arguments. Command accepts only one argument, which is a path to a solution file.")
}
program
.name('nuget-deps-tree')
.description("Nuget Dependency Tree Generator.")
.argument("<sln>", "solution file name")
.option('--text', "print it in plain text format")

if (["-h", "-help", "help"].includes(args[0])) {
console.info("nuget-deps-tree - Nuget Dependency Tree Generator.\nUsage: nuget-deps-tree [path to sln file]")
process.exit(0)
}
program.parse();

const options = program.opts();

const depsTree: any = NugetDepsTree.generate(args[0])
const depsTree: any = NugetDepsTree.generate(program.args[0])

function print(tree: DependencyTree, level: number = 0) {
const prefix = " ".repeat(level)
Expand All @@ -24,6 +25,10 @@ function printProject(project: Project) {
project.dependencies.forEach((dep: any) => print(dep, 1))
}

depsTree.projects.forEach((project: Project) => printProject(project))

// console.info(JSON.stringify(depsTree, null, 2))
if(options.text)
{
depsTree.projects.forEach((project: Project) => printProject(project))
} else
{
console.info(JSON.stringify(depsTree, null, 2))
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"dist/**/*"
],
"dependencies": {
"commander": "^12.0.0",
"fast-xml-parser": "^4.3.2",
"fs-extra": "^9.0.1",
"lodash": "^4.17.21",
Expand All @@ -53,7 +54,7 @@
"jest": "^29.3.1",
"prettier": "^2.0.5",
"ts-jest": "^29.0.3",
"typescript": "^4.9.4"
"typescript": "^5.4.5"
},
"keywords": [
"nuget",
Expand Down

0 comments on commit 600b9b8

Please sign in to comment.