Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
fix & update doctor fix command, add strings tool in sc
Browse files Browse the repository at this point in the history
  • Loading branch information
abdfnx committed Mar 12, 2022
1 parent c7a0be5 commit 1e2091b
Show file tree
Hide file tree
Showing 13 changed files with 822 additions and 440 deletions.
4 changes: 2 additions & 2 deletions app/doctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func DoctorCMD(buildVersion string) *cobra.Command {
func FixCMD(buildVersion string) *cobra.Command {
cmd := &cobra.Command{
Use: "fix",
Short: "Fix secman issues and bugs.",
Long: "Fix secman issues and bugs.",
Short: "Show Information about how to fix secman issues and bugs.",
Long: "Show Information about how to fix secman issues and bugs.",
Run: func(cmd *cobra.Command, args []string) {
doctor.Fix(buildVersion)
},
Expand Down
4 changes: 0 additions & 4 deletions core/contents/helpers/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ export async function root() {
console.log(
withSecondary(" $ secman edit --[PASSWORD_TYPE] <PASSWORD_NAME>\n")
);
console.log(cmd(" -") + " Generate\n");
console.log(withSecondary(" $ secman generate\n"));
console.log(cmd(" -") + " Edit Settings\n");
console.log(withSecondary(" $ secman settings\n"));
console.log(cmd("TELL US\n", true));
console.log(
` Open an issue at ${bold("https://github.com/scmn-dev/secman/issues")}\n`
Expand Down
10 changes: 6 additions & 4 deletions core/contents/helpers/topic.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import indent from "indent-string";
import stripAnsi from "strip-ansi";
import {
indentString as indent,
stripAnsi as strip,
wrapAnsi as wrap,
} from "../../tools/strings";
import { command } from "../../design/layout";
const wrap = require("wrap-ansi");
import { compact } from "../../tools/bool";

export function TopicFormatter(
Expand Down Expand Up @@ -38,7 +40,7 @@ export function TopicFormatter(
].join("\n"),
]).join("\n\n");

if (opts.stripAnsi) output = stripAnsi(output);
if (opts.strip) output = strip(output);

return output + "\n";
}
19 changes: 0 additions & 19 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,19 @@
"@oclif/plugin-help": "5.1.12",
"@oclif/plugin-not-found": "^2.2.1",
"@secman/spinner": "0.1.3",
"ansi-regex": "5.0.1",
"axios": "^0.26.1",
"bl": "^5.0.0",
"cfonts": "2.10.0",
"chalk": "^4.1.2",
"cli-ux": "^6.0.9",
"crypto-js": "^4.1.1",
"dotenv": "^16.0.0",
"globby": "^10",
"indent-string": "5.0.0",
"lodash": "4.17.21",
"lodash.template": "^4.5.0",
"powershell": "^2.3.2",
"prettier": "2.5.1",
"process": "^0.11.10",
"prompts": "^2.4.2",
"rimraf": "3.0.2",
"shelljs": "0.8.5",
"signal-exit": "^3.0.5",
"string-width": "4.2.3",
"strip-ansi": "6.0.1",
"ts-node": "^10",
"tslib": "^2",
"typescript": "^4.5.5",
"wcwidth": "^1.0.1",
"whatwg-fetch": "^3.6.2",
"wrap-ansi": "6.2.0",
"write-file-atomic": "^4.0.1"
},
"devDependencies": {
Expand All @@ -70,13 +56,8 @@
"@types/crypto-js": "^4.0.2",
"@types/lodash.template": "^4.5.0",
"@types/node": "^17.0.21",
"@types/prompts": "^2.0.14",
"@types/shelljs": "^0.8.9",
"@types/signal-exit": "^3.0.1",
"@types/whatwg-fetch": "^0.0.33",
"@types/wrap-ansi": "^8.0.1",
"@types/write-file-atomic": "^4.0.0",
"@types/yargs": "^17.0.4",
"follow-redirects": "^1.14.8",
"node-fetch": "^3.2.2"
},
Expand Down
5 changes: 2 additions & 3 deletions core/src/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import { bold, command, withSecondary } from "../design/layout";
import { HelpBase } from "@oclif/core";
import { Command } from "@oclif/core/lib/interfaces";
import * as Interfaces from "@oclif/core/lib/interfaces";

import { indentString as indent } from "../tools/strings";
const { say } = require("cfonts");
const { sortBy, uniqBy } = require("../tools/bool");
const { renderList } = require("../tools/list");
const indent = require("indent-string");
const { CommandHelp } = require("../tools/help-command");
const root = require("../contents/helpers/root");
const { TopicFormatter } = require("../contents/helpers/topic");
Expand Down Expand Up @@ -95,7 +94,7 @@ module.exports = class MyHelpClass extends HelpBase {
console.log("");
}

return root.end()
return root.end();
}

async showRootHelp() {
Expand Down
156 changes: 0 additions & 156 deletions core/tools/detect-indent.ts

This file was deleted.

6 changes: 2 additions & 4 deletions core/tools/help-command.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import * as Config from "@oclif/config";
import indent from "indent-string";
import stripAnsi from "strip-ansi";
import { indentString as indent, wrapAnsi as wrap, stripAnsi as strip } from "./strings"
import { renderList } from "./list";
import { castArray, compact, sortBy, template } from "./bool";
import wrap from "wrap-ansi";
import { command, dim, underline, withSecondary } from "../design/layout";

export interface HelpOptions {
Expand Down Expand Up @@ -43,7 +41,7 @@ export class CommandHelp {
this.aliases(cmd.aliases),
this.examples(cmd.examples || (cmd as any).example),
]).join("\n\n");
if (this.opts.stripAnsi) output = stripAnsi(output);
if (this.opts.stripAnsi) output = strip(output);
return output;
}

Expand Down
6 changes: 3 additions & 3 deletions core/tools/json/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as path from "path";
import * as fs from "fs";
import { promises as fsPromises } from "fs";
import { isPlainObject as isPlainObj, sortKeys } from "../sort";
import detectIndent from "../detect-indent";
import { detectIndent as detect } from "../strings";
const writeFileAtomic = require("write-file-atomic");

const init = (function_: any, filePath: any, data: any, options: any) => {
Expand Down Expand Up @@ -41,7 +41,7 @@ const main = async (filePath: any, data: any, options: any) => {
}

if (options.detectIndent) {
indent = detectIndent(file).indent;
indent = detect(file).indent;
}
} catch (error) {
throw error;
Expand All @@ -65,7 +65,7 @@ const mainSync = (filePath: any, data: any, options: any) => {
}

if (options.detectIndent) {
indent = detectIndent(file).indent;
indent = detect(file).indent;
}
} catch (error) {
throw error;
Expand Down
23 changes: 11 additions & 12 deletions core/tools/list.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import indent from "indent-string";
import stripAnsi from "strip-ansi";
import width from "string-width";
import wrap from "wrap-ansi";
import widestLine from "widest-line";
import {
indentString as indent,
stripAnsi as strip,
stringWidth as width,
wrapAnsi as wrap,
widestLine,
} from "./strings";

export function renderList(
input: (string | undefined)[][],
Expand All @@ -23,12 +25,12 @@ export function renderList(
for (let [left, right] of input) {
if (!left && !right) continue;
if (left) {
if (opts.stripAnsi) left = stripAnsi(left);
if (opts.stripAnsi) left = strip(left);
output += wrap(left.trim(), opts.maxWidth, { hard: true, trim: false });
}

if (right) {
if (opts.stripAnsi) right = stripAnsi(right);
if (opts.stripAnsi) right = strip(right);

output += "\n";
output += indent(
Expand Down Expand Up @@ -59,20 +61,19 @@ export function renderList(

cur = left || "";

if (opts.stripAnsi) cur = stripAnsi(cur);
if (opts.stripAnsi) cur = strip(cur);
if (!right) {
cur = cur.trim();
continue;
}

if (opts.stripAnsi) right = stripAnsi(right);
if (opts.stripAnsi) right = strip(right);

right = wrap(right.trim(), opts.maxWidth - (maxLength + 2), {
hard: true,
trim: false,
});

// right = wrap(right.trim(), screen.stdtermwidth - (maxLength + 4), {hard: true, trim: false})
const [first, ...lines] = right!.split("\n").map((s) => s.trim());

cur += " ".repeat(maxLength - width(cur) + 2);
Expand All @@ -82,9 +83,7 @@ export function renderList(
continue;
}

// if we start putting too many lines down, render in multiline format
if (lines.length > 4) return renderMultiline();
// if spacer is not defined, separate all rows with extra newline
if (!opts.spacer) spacer = "\n\n";

cur += "\n";
Expand Down
Loading

0 comments on commit 1e2091b

Please sign in to comment.