Very new to puppet here.
Suppose:
define add_user ($shell) {
$username = $title
user { $username:
shell = $shell,
}
group { $username:
require => User[$username]
}
}
And:
class zsh {
package { 'zsh': ensure => 'installed' }
}
class bash {
package { 'bash': ensure => 'installed' }
}
And finally:
node default {
add_user { 'foo':
shell => '/bin/zsh'
}
}
How do I set up a requirement from the user to the shell?
Try to add something like this to your add_user function:
define add_user ($shell) {
case $shell {
'/bin/zsh': { include zsh }
'/bin/bash': { include bash }
default: { fail('Unknown Shell') }
}
...
}
Related
In tiptap2, I have two custom extensions that add a class versus a style because I am utilizing tailwindcss, which leverages classes exclusively, not inline styles.
So, the first one adds 'class="text-green-500"' (or whatever) and likewise, 'class="bg-green-500"'. I extend TextStyle in both custom extensions to allow for class versus span. I believe the answer lies in extending textstyle once, but I'm not sure how to go about that and catch both outcomes.
I can't combine the two by having a highlight span and a color span together.
If I take the following:
and then try and say make the "w" a different color, I get:
What I want to achieve is "Howdy" with complete cyan while still able to apply individual font colors within the outer span (or vice-versa).
import { TextStyle } from '#tiptap/extension-text-style';
export const HighlightColorStyle = TextStyle.extend({
parseHTML() {
return [
{
tag: 'span',
getAttrs: (node) => /text|bg-[\w]*-[1-9]00/.test(node.className)
}
];
}
});
export const HighlightColor = Extension.create({
name: 'highlightColor',
addGlobalAttributes() {
return [
{
types: ['textStyle'],
attributes: {
class: {
default: ''
}
}
}
];
},
addCommands() {
return {
setHighlightColor:
(color) =>
({ chain }) => {
console.log('hoadodoadfaf', color);
return chain().setMark('textStyle', { class: color });
},
toggleHighlightColor:
() =>
({ chain }) => {
return chain().toggleMark('textStyle');
},
unsetHighlightColor:
() =>
({ chain }) => {
return chain().setMark('textStyle', { class: null }).removeEmptyTextStyle();
}
};
}
});
and
import { Extension } from '#tiptap/core';
import { TextStyle } from '#tiptap/extension-text-style';
export const TextColorStyle = TextStyle.extend({
parseHTML() {
return [
{
tag: 'span',
getAttrs: node => /text-[\w]*-[1-9]00/.test(node.className)
}
];
}
});
export const TextColor = Extension.create({
name: 'textColor',
addGlobalAttributes() {
return [
{
types: ['textStyle'],
attributes: {
class: {
default: ''
} }
}
];
},
addCommands() {
return {
setTextColor:
color =>
({ chain }) => {
console.log('hoadodoadfaf', color)
return chain().setMark('textStyle', { class: color });
},
toggleTextColor:
() =>
({ chain }) => {
return chain().toggleMark('textStyle');
},
unsetTextColor:
() =>
({ chain }) => {
return chain().setMark('textStyle', { class: null }).removeEmptyTextStyle();
}
};
}
});
You should treat class as object not string, so the multi class can combine, then add a ClassExtension to apply the class to a tag.
The ClassExtension is works like textStyle, except it will apply the class, textStyle dose not apply styles, because styles is an object, applied by individual Extension.
Write a simple classNames extension based on a modified testStyle extension.
I have a project in Node JS and Typescript in which I have a file with a class that I use to check that a directory exists and create another. To the method I pass two parameters, the main directory ('src/out') and a string with which to create the following directory ('api').
This is my class, the dir variable ('src / out') and the api variable ('api'):
export class createDir {
checkExistsOrCreate(dir: string, api: any) {
let dire = `${dir}${api}`;
if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
}
if (fs.existsSync(dire)) {
rimraf.sync(dire);
fs.mkdirSync(dire);
}else {
fs.mkdirSync(dire);
}
return dire;
}
}
What I want to do is create two functions: the first one I pass the main directory ('src / out') and it checks if it exists. And the second creates the directories, if the principal does not exist, it creates the principal directory and the api directory ('src / out / api') and if the principal exists it will only create the '/ api' directory.
My problem is that I don't know how to separate both functions and how to tell the second if the main directory exists or not.
This is the first function that only checks that the directory that reaches it exists:
export class exists {
exitsDir(dir: string) {
if (!fs.existsSync(dir)){
return false;
}else{
return true;
}
}
}
This is the class from which I call the directory check and pass the directory to check:
class UtilsController {
public async utilsDir () {
try {
let checkDir = new exists();
await checkDir.exitsDir('src/out');
} catch (error) {
console.log(error);
}
}
}
Actually the mkdir function can handle your use case automatically when using the recursive option.
const fs = require('fs');
fs.mkdirSync('main/sub', {recursive: true});
There are a lot of classes that are not really needed but this should work:
class UtilsController {
public utilsDir(): Promise<boolean> {
try {
const checkDir = new exists();
return checkDir.exitsDir('src/out');
} catch (error) {
console.log(error);
}
}
}
const test = async () => {
const utilsController = new UtilsController();
const exists = await utilsController.utilsDir();
console.log(exists);
};
def parallelIntegrationTests(stages) {
def tests = stages.collectEntries{ stagename, config ->
config = [solr: true, failonerror: true]
[(stagename): {
stage(stagename) {
node('integration && php7.1') {
ws('/var/lib/jenkins/shared-workspace/in-integration') {
try {
if (config.solr) {
sh "/usr/bin/ant -buildfile in/build.xml -Dphpunit.integration.group=${stagename} -Dphpunit.integration.failonerror=${config.failonerror} integration"
} else {
sh "/usr/bin/ant -buildfile in/build.xml integration-functional"
}
} catch (e) {
throw e
}
}
}
}
}]
}
parallel tests
}
parallelIntegrationTests(
[
'integration-functional': {solr: false},
'security-authentication': {},
'api-infra': {},
'external-dependencies': {failonerror: false},
'registration': {}
]
)
I'm trying to handle the if else condition based on the parameter send from the function. But When ever the jenkinsfile is running and the parallelIntegrationTests is called, config parameter "config = [solr: true, failonerror: true]" set locally is overriding the parameter send from the calling fuction. How do I handle this?
The correct function is :
def parallelIntegrationTests(stages) {
def tests = stages.collectEntries{ stagename, config ->
config = [solr: true, failonerror: true] + config
[(stagename): {
stage(stagename) {
node('integration && php7.1') {
ws('/var/lib/jenkins/shared-workspace/in-integration') {
try {
if (config.solr) {
sh "/usr/bin/ant -buildfile in/build.xml -Dphpunit.integration.group=${stagename} -Dphpunit.integration.failonerror=${config.failonerror} integration"
} else {
sh "/usr/bin/ant -buildfile in/build.xml integration-functional"
}
} catch (e) {
throw e
}
}
}
}
}]
}
parallel tests
I have a middleware that exports context.isMobile. I can access it from layout like this:
layout (ctx) {
if(ctx.isMobile) {
return 'mobile'
} else if (ctx.isDesktop) {
return 'default'
}
},
...but I can't access the context from data or computed. How do I get the context there?
You can access the context via this.$nuxt.context like this:
export default {
data() {
console.log(this.$nuxt.context)
return { /*...*/ }
},
computed: {
myProp() {
console.log(this.$nuxt.context)
return 'foo'
}
}
}
i try to connect my frontend to my backend,
the request is done correctly i received the correct data, but the DOM is not updating. I use this.$nextTick but it doesn't affect the update
in the template i use {{ system.CPU.avgload }}
like i said the fetch is done correctly it pass into nexttick, but nothing change
in the main vue i have this
import System from '../utils/system'
import Auth from '../utils/auth'
export default {
created: function () {
this.system = {
CPU: {
avgload: 0
}
}
},
mounted: function () {
this.fetchData()
setInterval(function () {
this.fetchData()
}.bind(this), 10000)
},
methods: {
fetchData () {
if (!Auth.checkAuth) {
console.log('test')
this.error = true
} else {
var self = this
this.$nextTick(function () {
System.Get(function (response) {
self.system = response
})
})
}
}
}
}
and the template is
<div class="text-xs-left" id="example-caption-1">CPU : {{ system.CPU.avgload }} %</div>
You have to add variable system in the data section of vue instance. Than only this variable will become reactive and available in the HTML.
export default {
data: function () {
return { system: {
CPU: {
avgload : ""
}
}
}
}
...
...