Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/987 allow using --like option similar to SQL's LIKE logic #1006

86 changes: 78 additions & 8 deletions docs/dist/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,9 @@ main class
* [.buildDefinition(businessUnit, selectedType, name, market)](#Mcdev.buildDefinition) ⇒ <code>Promise.&lt;void&gt;</code>
* [.buildDefinitionBulk(listName, type, name)](#Mcdev.buildDefinitionBulk) ⇒ <code>Promise.&lt;void&gt;</code>
* [.getFilesToCommit(businessUnit, selectedType, keyArr)](#Mcdev.getFilesToCommit) ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code>
* [.execute(businessUnit, [selectedTypesArr], keys)](#Mcdev.execute) ⇒ <code>Promise.&lt;boolean&gt;</code>
* [._executeBU(cred, bu, [selectedTypesArr], keyArr)](#Mcdev._executeBU) ⇒ <code>Promise.&lt;boolean&gt;</code>
* [.execute(businessUnit, [selectedType], [keys])](#Mcdev.execute) ⇒ <code>Promise.&lt;boolean&gt;</code>
* [._executeBU(cred, bu, [type], keyArr)](#Mcdev._executeBU) ⇒ <code>Promise.&lt;boolean&gt;</code>
* [._retrieveKeysWithLike(selectedType, buObject)](#Mcdev._retrieveKeysWithLike) ⇒ <code>Array.&lt;string&gt;</code>

<a name="Mcdev.setSkipInteraction"></a>

Expand Down Expand Up @@ -751,7 +752,7 @@ Build a specific metadata file based on a template using a list of bu-market com

<a name="Mcdev.execute"></a>

### Mcdev.execute(businessUnit, [selectedTypesArr], keys) ⇒ <code>Promise.&lt;boolean&gt;</code>
### Mcdev.execute(businessUnit, [selectedType], [keys]) ⇒ <code>Promise.&lt;boolean&gt;</code>
Start an item (query)

**Kind**: static method of [<code>Mcdev</code>](#Mcdev)
Expand All @@ -760,13 +761,13 @@ Start an item (query)
| Param | Type | Description |
| --- | --- | --- |
| businessUnit | <code>string</code> | name of BU |
| [selectedTypesArr] | <code>Array.&lt;TYPE.SupportedMetadataTypes&gt;</code> | limit to given metadata types |
| keys | <code>Array.&lt;string&gt;</code> | customerkey of the metadata |
| [selectedType] | <code>TYPE.SupportedMetadataTypes</code> | limit to given metadata types |
| [keys] | <code>Array.&lt;string&gt;</code> | customerkey of the metadata |

<a name="Mcdev._executeBU"></a>

### Mcdev.\_executeBU(cred, bu, [selectedTypesArr], keyArr) ⇒ <code>Promise.&lt;boolean&gt;</code>
helper for [execute](execute)
### Mcdev.\_executeBU(cred, bu, [type], keyArr) ⇒ <code>Promise.&lt;boolean&gt;</code>
helper for [execute](#Mcdev.execute)

**Kind**: static method of [<code>Mcdev</code>](#Mcdev)
**Returns**: <code>Promise.&lt;boolean&gt;</code> - true if all items were executed, false otherwise
Expand All @@ -775,9 +776,22 @@ helper for [execute](execute)
| --- | --- | --- |
| cred | <code>string</code> | name of Credential |
| bu | <code>string</code> | name of BU |
| [selectedTypesArr] | <code>Array.&lt;TYPE.SupportedMetadataTypes&gt;</code> | limit execution to given metadata type |
| [type] | <code>TYPE.SupportedMetadataTypes</code> | limit execution to given metadata type |
| keyArr | <code>Array.&lt;string&gt;</code> | customerkey of the metadata |

<a name="Mcdev._retrieveKeysWithLike"></a>

### Mcdev.\_retrieveKeysWithLike(selectedType, buObject) ⇒ <code>Array.&lt;string&gt;</code>
helper for [_executeBU](#Mcdev._executeBU)

**Kind**: static method of [<code>Mcdev</code>](#Mcdev)
**Returns**: <code>Array.&lt;string&gt;</code> - keyArr

| Param | Type | Description |
| --- | --- | --- |
| selectedType | <code>TYPE.SupportedMetadataTypes</code> | limit execution to given metadata type |
| buObject | <code>TYPE.BuObject</code> | properties for auth |

<a name="Asset"></a>

## Asset ⇐ [<code>MetadataType</code>](#MetadataType)
Expand Down Expand Up @@ -5892,6 +5906,8 @@ CLI entry for SFMC DevTools
* [.getKeysString(keyArr, [isId])](#Util.getKeysString) ⇒ <code>string</code>
* [.sleep(ms)](#Util.sleep) ⇒ <code>Promise.&lt;void&gt;</code>
* [.getSsjs(code)](#Util.getSsjs) ⇒ <code>string</code>
* [.stringLike(testString, search)](#Util.stringLike) ⇒ <code>boolean</code>
* [.fieldsLike(metadata, [filters])](#Util.fieldsLike) ⇒ <code>boolean</code>

<a name="Util.skipInteraction"></a>

Expand Down Expand Up @@ -6248,6 +6264,32 @@ the following is invalid:
// 3
</script>
```
<a name="Util.stringLike"></a>

### Util.stringLike(testString, search) ⇒ <code>boolean</code>
allows us to filter just like with SQL's LIKE operator

**Kind**: static method of [<code>Util</code>](#Util)
**Returns**: <code>boolean</code> - true if testString matches search

| Param | Type | Description |
| --- | --- | --- |
| testString | <code>string</code> | field value to test |
| search | <code>string</code> | search string in SQL LIKE format |

<a name="Util.fieldsLike"></a>

### Util.fieldsLike(metadata, [filters]) ⇒ <code>boolean</code>
returns true if no LIKE filter is defined or if all filters match

**Kind**: static method of [<code>Util</code>](#Util)
**Returns**: <code>boolean</code> - true if no LIKE filter is defined or if all filters match

| Param | Type | Description |
| --- | --- | --- |
| metadata | <code>TYPE.MetadataTypeItem</code> | a single metadata item |
| [filters] | <code>object</code> | only used in recursive calls |

<a name="MetadataTypeDefinitions"></a>

## MetadataTypeDefinitions
Expand Down Expand Up @@ -7782,6 +7824,8 @@ Util that contains logger and simple util methods
* [.getKeysString(keyArr, [isId])](#Util.getKeysString) ⇒ <code>string</code>
* [.sleep(ms)](#Util.sleep) ⇒ <code>Promise.&lt;void&gt;</code>
* [.getSsjs(code)](#Util.getSsjs) ⇒ <code>string</code>
* [.stringLike(testString, search)](#Util.stringLike) ⇒ <code>boolean</code>
* [.fieldsLike(metadata, [filters])](#Util.fieldsLike) ⇒ <code>boolean</code>

<a name="Util.skipInteraction"></a>

Expand Down Expand Up @@ -8138,6 +8182,32 @@ the following is invalid:
// 3
</script>
```
<a name="Util.stringLike"></a>

### Util.stringLike(testString, search) ⇒ <code>boolean</code>
allows us to filter just like with SQL's LIKE operator

**Kind**: static method of [<code>Util</code>](#Util)
**Returns**: <code>boolean</code> - true if testString matches search

| Param | Type | Description |
| --- | --- | --- |
| testString | <code>string</code> | field value to test |
| search | <code>string</code> | search string in SQL LIKE format |

<a name="Util.fieldsLike"></a>

### Util.fieldsLike(metadata, [filters]) ⇒ <code>boolean</code>
returns true if no LIKE filter is defined or if all filters match

**Kind**: static method of [<code>Util</code>](#Util)
**Returns**: <code>boolean</code> - true if no LIKE filter is defined or if all filters match

| Param | Type | Description |
| --- | --- | --- |
| metadata | <code>TYPE.MetadataTypeItem</code> | a single metadata item |
| [filters] | <code>object</code> | only used in recursive calls |

<a name="csvToArray"></a>

## csvToArray(csv) ⇒ <code>Array.&lt;string&gt;</code>
Expand Down
34 changes: 25 additions & 9 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ yargs
.positional('KEY', {
type: 'string',
describe: 'metadata keys that shall be exclusively downloaded',
})
.option('like', {
type: 'string',
group: 'Options for retrieve:',
describe:
'filter metadata components (can include % as wildcard or _ for a single character)',
});
},
handler: (argv) => {
Expand All @@ -57,31 +63,32 @@ yargs
type: 'string',
describe: 'metadata key that shall be exclusively uploaded',
})
.group(
['changeKeyField', 'changeKeyValue', 'fromRetrieve', 'refresh', 'execute'],
'Options for deploy:'
)
.option('changeKeyField', {
type: 'string',
group: 'Options for deploy:',
describe:
'enables updating the key of the deployed metadata with the value in provided field (e.g. c__newKey). Can be used to sync name and key fields.',
})
.option('changeKeyValue', {
type: 'string',
group: 'Options for deploy:',
describe:
'allows updating the key of the metadata to the provided value. Only available if a single type and key is deployed',
})
.option('fromRetrieve', {
type: 'boolean',
group: 'Options for deploy:',
describe: 'optionally deploy from retrieve folder',
})
.option('refresh', {
type: 'boolean',
group: 'Options for deploy:',
describe:
'optional for asset-message: runs refresh command for related triggeredSends after deploy',
})
.option('execute', {
type: 'boolean',
group: 'Options for deploy:',
describe: 'optional for query: runs execute after deploy',
});
},
Expand Down Expand Up @@ -313,8 +320,9 @@ yargs
aliases: ['et'],
desc: 'explains metadata types that can be retrieved',
builder: (yargs) => {
yargs.group(['json'], 'Options for explainTypes:').option('json', {
yargs.option('json', {
type: 'boolean',
group: 'Options for explainTypes:',
describe: 'optionaly return info in json format',
});
},
Expand All @@ -333,14 +341,15 @@ yargs
type: 'string',
describe: 'Pull Request target branch or git commit range',
})
.group(['filter', 'commitHistory'], 'Options for createDeltaPkg:')
.option('filter', {
type: 'string',
group: 'Options for createDeltaPkg:',
describe:
'Disable templating & instead filter by the specified BU path (comma separated), can include subtype, will be prefixed with "retrieve/"',
})
.option('commitHistory', {
type: 'number',
group: 'Options for createDeltaPkg:',
describe: 'Number of commits to look back for changes (supersedes config)',
});
},
Expand Down Expand Up @@ -399,8 +408,8 @@ yargs
},
})
.command({
command: 'execute <BU> <TYPE> <KEY>',
aliases: ['exec'],
command: 'execute <BU> <TYPE> [KEY]',
aliases: ['exec', 'start'],
desc: 'executes the entity (query/journey/automation etc.)',
builder: (yargs) => {
yargs
Expand All @@ -415,11 +424,18 @@ yargs
.positional('KEY', {
type: 'string',
describe: 'key(s) of the metadata component(s)',
})
.option('like', {
type: 'string',
group: 'Options for execute:',
describe:
'filter metadata components (can include % as wildcard or _ for a single character)',
});
},
handler: (argv) => {
Mcdev.setOptions(argv);
Mcdev.execute(argv.BU, csvToArray(argv.TYPE), csvToArray(argv.KEY));
// ! do not allow multiple types to be passed in here via csvToArray
Mcdev.execute(argv.BU, argv.TYPE, csvToArray(argv.KEY));
},
})
.command({
Expand Down
Loading