Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add "clean" = false option#44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ShMcK merged 4 commits intomasterfromfixes
Jun 20, 2020
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletionssrc/help.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -47,6 +47,7 @@ Usage: coderoad validate [path] [options]

Options:
--help (-h) display these help docs
--clean (-c) set to false to preserve .tmp folder. Helpful for debugging

More docs at https://github.com/coderoad/coderoad-cli`);
}
68 changes: 50 additions & 18 deletionssrc/utils/args.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,64 @@
typeArgValueParams={name:string;alias?:string;param?:boolean};
typeArgValueParams={
name:string;
alias?:string;
type?:"string"|"bool"|"number";
};

constcheckValue=(
functioncheckValue<T>(
args:string[],
string:string,
options:ArgValueParams
)=>{
isBool:boolean
):string|null{
constnameIndex=args.indexOf(string);
if(nameIndex>-1){
if(options.param){
constvalue=args[nameIndex+1];
if(!value){
thrownewError(`Argument${string} is missing a parameter value`);
if(nameIndex>=0){
constnextArg=args[nameIndex+1];

if(nextArg!==undefined){
constnextIsCommand=!!nextArg.match(/^\-/);
if(nextIsCommand){
returnisBool ?"true" :null;
}
returnvalue;
returnnextArg;
}else{
// no secondary set value
returnisBool ?"true" :null;
}
}
returnnull;
};
}

exportfunctiongetArg(args:string[],options:ArgValueParams):string|null{
letvalue:null|string=null;
exportfunctiongetArg<T>(
args:string[],
options:ArgValueParams
):string|boolean|number|null{
letstringValue:null|string=null;
constisBool=options.type==="bool";

constaliasString=`-${options.alias}`;
value=checkValue(args,aliasString,options);
if(!value){
if(options.alias){
constaliasString=`-${options.alias}`;
stringValue=checkValue(args,aliasString,isBool);
}
if(!stringValue){
constnameString=`--${options.name}`;
value=checkValue(args,nameString,options);
stringValue=checkValue(args,nameString,isBool);
}

if(stringValue===null){
returnnull;
}

returnvalue;
if(!options.type){
options.type="string";
}

// coerce type
switch(options.type){
case"bool":
return(stringValue||"").toLowerCase()!=="false";
case"number":
returnNumber(stringValue);
case"string":
default:
returnstringValue;
}
}
7 changes: 6 additions & 1 deletionsrc/utils/exec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,14 +22,18 @@ export function createCherryPick(cwd: string) {
return async function cherryPick(commits: string[]): Promise<void> {
for (const commit of commits) {
try {
const { stdout } = await createExec(cwd)(
const { stdout, stderr } = await createExec(cwd)(
`git cherry-pick -X theirs ${commit}`
);
if (stderr) {
console.warn(stderr);
}
if (!stdout) {
console.warn(`No cherry-pick output for ${commit}`);
}
} catch (e) {
console.warn(`Cherry-pick failed for ${commit}`);
console.error(e.message);
}
}
};
Expand All@@ -50,6 +54,7 @@ export function createCommandRunner(cwd: string) {
}
const { stdout, stderr } = await createExec(cwdDir)(command);

console.log(stdout);
console.warn(stderr);
} catch (e) {
console.error(`Command failed: "${command}"`);
Expand Down
24 changes: 20 additions & 4 deletionssrc/validate.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,17 +10,30 @@ import {
} from "./utils/exec";
import { getCommits, CommitLogObject } from "./utils/commits";

interface Options {
yaml: string;
clean: boolean;
}

async function validate(args: string[]) {
// dir - default .
const dir = !args.length || args[0].match(/^-/) ? "." : args[0];
const localDir = path.join(process.cwd(), dir);

// -y --yaml - default coderoad-config.yml
const options = {
yaml: getArg(args, { name: "yaml", alias: "y" }) || "coderoad.yaml",
const options: Options = {
// @ts-ignore
yaml:
getArg(args, { name: "yaml", alias: "y", type: "string" }) ||
"coderoad.yaml",
// @ts-ignore
clean: getArg(args, { name: "clean", alias: "c", type: "bool" }),
};

const _yaml = await fs.readFile(path.join(localDir, options.yaml), "utf8");
const _yaml: string = await fs.readFile(
path.join(localDir, options.yaml),
"utf8"
);

// parse yaml config
let skeleton;
Expand DownExpand Up@@ -158,7 +171,10 @@ async function validate(args: string[]) {
console.error(e.message);
} finally {
// cleanup
await fs.emptyDir(tmpDir);
console.log("options.clean", options.clean);
if (options.clean) {
await fs.emptyDir(tmpDir);
}
}
}

Expand Down
69 changes: 69 additions & 0 deletionstests/args.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
import { getArg } from "../src/utils/args";

describe("args", () => {
it("should capture an arg name from text", () => {
const args = ["--name", "value"];
const result = getArg(args, { name: "name" });
expect(result).toBe("value");
});
it("should capture an arg alias from text", () => {
const args = ["-n", "value"];
const result = getArg(args, { name: "name", alias: "n" });
expect(result).toBe("value");
});
it("should capture an arg name from text when starting values", () => {
const args = ["dir", "--name", "value"];
const result = getArg(args, { name: "name" });
expect(result).toBe("value");
});
it("should capture an arg alias from text", () => {
const args = ["dir", "-n", "value"];
const result = getArg(args, { name: "name", alias: "n" });
expect(result).toBe("value");
});
it("should convert bool string to true", () => {
const args = ["--someBool", "true"];
const result = getArg(args, {
name: "someBool",
alias: "sb",
type: "bool",
});
expect(result).toBe(true);
});
it("should convert bool string to false", () => {
const args = ["--someBool", "false"];
const result = getArg(args, {
name: "someBool",
alias: "sb",
type: "bool",
});
expect(result).toBe(false);
});
it("should default value to true if no next value", () => {
const args = ["--someBool"];
const result = getArg(args, {
name: "someBool",
alias: "sb",
type: "bool",
});
expect(result).toBe(true);
});
it("should default value to true if next value is --name", () => {
const args = ["--someBool", "--someOtherBool"];
const result = getArg(args, {
name: "someBool",
alias: "sb",
type: "bool",
});
expect(result).toBe(true);
});
it("should default value to true if next value is -alias", () => {
const args = ["--someBool", "-a"];
const result = getArg(args, {
name: "someBool",
alias: "sb",
type: "bool",
});
expect(result).toBe(true);
});
});

[8]ページ先頭

©2009-2025 Movatter.jp