diff --git a/src/cmd.ts b/src/cmd.ts index 8ea07e1..59baa27 100644 --- a/src/cmd.ts +++ b/src/cmd.ts @@ -5,7 +5,6 @@ import { LogLevel, ScaffoldCmdConfig } from "./types" import { Scaffold } from "./scaffold" import path from "path" import fs from "fs/promises" -import { OptionsBase } from "massarg/types" import { parseAppendData } from "./utils" export async function parseCliArgs(args = process.argv.slice(2)) { @@ -13,7 +12,11 @@ export async function parseCliArgs(args = process.argv.slice(2)) { return ( massarg() - .main(Scaffold) + .main((config) => { + config.data = { ...config.data, ...config.appendData } + delete config.appendData + return Scaffold(config) + }) .option({ name: "name", aliases: ["n"], diff --git a/src/types.ts b/src/types.ts index b67a0d9..57896c9 100644 --- a/src/types.ts +++ b/src/types.ts @@ -331,6 +331,7 @@ export interface ScaffoldCmdConfig { output: string createSubFolder: boolean data?: Record + appendData?: Record overwrite: boolean quiet: boolean verbose: LogLevel diff --git a/src/utils.ts b/src/utils.ts index 09ba584..3ca033c 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -389,5 +389,9 @@ export function parseAppendData(value: string, options: ScaffoldCmdConfig & Opti if (value.includes(":=") && !val.includes(":=")) { return { ...data, [key]: JSON.parse(val) } } - return { ...data, [key]: val } + return { ...data, [key]: isWrappedWithQuotes(val) ? val.substring(1, val.length - 1) : val } +} + +function isWrappedWithQuotes(string: string): boolean { + return (string.startsWith('"') && string.endsWith('"')) || (string.startsWith("'") && string.endsWith("'")) } diff --git a/tests/utils.test.ts b/tests/utils.test.ts index 83f4cb8..437f05b 100644 --- a/tests/utils.test.ts +++ b/tests/utils.test.ts @@ -116,5 +116,9 @@ describe("Utils", () => { test("overwrites existing value", () => { expect(parseAppendData("name:=123", blankCliConf)).toEqual({ name: 123 }) }) + + test("works with quotes", () => { + expect(parseAppendData('key="value test"', blankCliConf)).toEqual({ key: "value test", name: "test" }) + }) }) })