Skip to content

Commit

Permalink
Merge pull request #830 from salesforcecli/sm/pr-832-comment
Browse files Browse the repository at this point in the history
chore: refactor long fn out
  • Loading branch information
shetzel authored Dec 5, 2023
2 parents 30c43e9 + ca653b0 commit 571bc8f
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/commands/project/retrieve/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,18 +373,7 @@ const buildRetrieveAndDeleteTargets = async (
}
return result;
} else {
// check if we're retrieving metadata based on a pattern ...
let retrieveFromOrg: string | undefined;
if (flags.metadata) {
flags.metadata.some((mdEntry) => {
const mdName = mdEntry.split(':')[1];
if (mdName?.includes('*') && mdName?.length > 1 && !mdName?.includes('.*')) {
retrieveFromOrg = flags['target-org'].getUsername();
return true;
}
return false;
});
}
const retrieveFromOrg = flags.metadata?.some(isRegexMatch) ? flags['target-org'].getUsername() : undefined;

return {
componentSetFromNonDeletes: await ComponentSetBuilder.build({
Expand Down Expand Up @@ -412,7 +401,7 @@ const buildRetrieveAndDeleteTargets = async (
},
}
: {}),
org: retrieveFromOrg ? { username: retrieveFromOrg, exclude: [] } : undefined,
...(retrieveFromOrg ? { org: { username: retrieveFromOrg, exclude: [] } } : {}),
}),
};
}
Expand Down Expand Up @@ -449,3 +438,9 @@ const buildRetrieveOptions = async (
output: output ?? (await SfProject.resolve()).getDefaultPackage().fullPath,
}),
});

// check if we're retrieving metadata based on a pattern ...
const isRegexMatch = (mdEntry: string): boolean => {
const mdName = mdEntry.split(':')[1];
return mdName?.includes('*') && mdName?.length > 1 && !mdName?.includes('.*');
};

0 comments on commit 571bc8f

Please sign in to comment.