// include the latest version of the regex crate in your Cargo.toml
extern crate regex;
use regex::Regex;
fn main() {
let regex = Regex::new(r"(?m).*\((.|\n)+\)\s*\{").unwrap();
let string = "# @summary Manages the puppeteer monitor service.
#
# @param logon_domain
# The service will logon using this domain. Specify '.' for a local account.
#
# @param logon_name
# The service will logon using this user name.
#
# @param logon_password
# The service will logon using this password.
#
# @param ensure
# Whether or not install the puppeteermon service.
#
# @param source
# Where to obtain the puppeteermon service executable from.
#
# @param state
# Ensure the puppeteermon service is in the given `state`.
#
# @param startup
# How to start the puppeteermon service.
#
# @param version
# The version of the puppeteermon service that should be installed.
#
class profile::ct::puppeteermon(
String $logon_domain = \"${hiera('builder_domain', '.')}\",
String $logon_name = \"${hiera('builder_user', 'SYSTEM')}\",
String $logon_password = \"${hiera('builder_passwd', '')}\",
String $cooldown = '10m',
String $min_exec_time = '1m15s',
Enum[absent, present] $ensure = present,
String $source = 'https://repo.ct.activision.com/repository/puppet/puppeteermon/<%= ::osfamily %>/puppeteermon-<%= version %>',
Enum['running', 'stopped'] $state = 'running',
Enum['automatic', 'manual', 'disabled']
$startup = 'automatic',
String $version = '2.0.11',
) {
include profile::ct::puppeteer
if $::osfamily == 'windows' {
# Non-configurable class parameters
$basedir = 'C:/ProgramData/puppeteermon'
$os_source = regsubst($source, '<%= ::osfamily %>', 'windows', 'G')
$puppeteer_os_source = regsubst($profile::ct::puppeteer::source, '<%= ::osfamily %>', 'windows', 'G')
$puppeteer_fetch_source = regsubst($puppeteer_os_source, '<%= version %>', \"${profile::ct::puppeteer::version}.exe\", 'G')
$puppeteer_recovery_source = regsubst($puppeteer_os_source, '<%= version %>', 'recovery.exe', 'G')
profile::ct::puppeteer::config { \"${profile::ct::puppeteer::basedir}/puppeteer.conf\":
ensure => $ensure,
compass_master_url => $profile::ct::puppeteer::compass_master_url,
runinterval => $profile::ct::puppeteer::runinterval,
splay => $profile::ct::puppeteer::splay,
version => $profile::ct::puppeteer::version,
}
-> profile::ct::puppeteermon::config { \"${basedir}/puppeteermon.conf\":
ensure => $ensure,
cooldown => $cooldown,
fetch_url => $puppeteer_fetch_source,
download_dir => \"${profile::ct::puppeteer::basedir}/fetch\",
command => \"${profile::ct::puppeteer::basedir}/running/puppeteer.exe\",
}
profile::ct::puppeteer::config_new { \"${profile::ct::puppeteer::basedir}/puppeteer.yaml\":
ensure => $ensure,
compass_master_url => $profile::ct::puppeteer::compass_master_url,
compass_polling_interval => $profile::ct::puppeteer::compass_polling_interval,
runinterval => $profile::ct::puppeteer::runinterval,
last_run_summary => $profile::ct::puppeteer::last_run_summary,
splay => $profile::ct::puppeteer::splay,
version => $profile::ct::puppeteer::version,
agent_config_platform => $profile::ct::puppeteer::agent_config_platform,
}
-> profile::ct::puppeteermon::config_new { \"${basedir}/puppeteermon.yaml\":
ensure => $ensure,
cooldown => $cooldown,
fetch_url => $puppeteer_fetch_source,
recovery_url => $puppeteer_recovery_source,
download_dir => \"${profile::ct::puppeteer::basedir}/stage\",
command => \"${profile::ct::puppeteer::basedir}/running/puppeteer.exe\",
min_exec_time => $min_exec_time
}
-> wservice { 'puppeteermon':
ensure => $ensure,
state => $state,
startup => $startup,
source => regsubst($os_source, '<%= version %>', \"${version}.tar.gz\", 'G'),
version => $version,
path => \"${basedir}/puppeteermon.exe\",
account => \"${logon_domain}\\\\${logon_name}\",
password => $logon_password,
registercmd => ['<%= path %>', 'install'],
unregistercmd => ['<%= path %>', 'uninstall'],
}
if $ensure == present {
$enable = $startup ? { 'automatic' => 'true', 'manual' => 'manual', default => 'false' }
service { 'puppeteermon':
ensure => $state,
enable => $enable,
require => Wservice['puppeteermon']
}
}
} elsif $::osfamily == 'Darwin' {
# Non-configurable class parameters
$basedir = '/opt/puppeteermon'
$os_source = regsubst($source, '<%= ::osfamily %>', 'darwin', 'G')
$puppeteer_os_source = regsubst($profile::ct::puppeteer::source, '<%= ::osfamily %>', 'darwin', 'G')
$puppeteer_fetch_source = regsubst($puppeteer_os_source, '<%= version %>', $profile::ct::puppeteer::version, 'G')
$puppeteer_recovery_source = regsubst($puppeteer_os_source, '<%= version %>', 'recovery', 'G')
profile::ct::puppeteer::config_new { \"${profile::ct::puppeteer::basedir}/puppeteer.yaml\":
ensure => $ensure,
compass_master_url => $profile::ct::puppeteer::compass_master_url,
compass_polling_interval => $profile::ct::puppeteer::compass_polling_interval,
runinterval => $profile::ct::puppeteer::runinterval,
last_run_summary => $profile::ct::puppeteer::last_run_summary,
splay => $profile::ct::puppeteer::splay,
version => $profile::ct::puppeteer::version,
agent_config_platform => $profile::ct::puppeteer::agent_config_platform,
}
-> profile::ct::puppeteermon::config_new { \"${basedir}/puppeteermon.yaml\":
ensure => $ensure,
cooldown => $cooldown,
fetch_url => $puppeteer_fetch_source,
recovery_url => $puppeteer_recovery_source,
download_dir => \"${profile::ct::puppeteer::basedir}/stage\",
command => \"${profile::ct::puppeteer::basedir}/running/puppeteer\",
min_exec_time => $min_exec_time
}
-> puppeteermon { '/opt/puppeteermon/puppeteermon':
ensure => $ensure,
version => $version,
source => regsubst($os_source, '<%= version %>', $version, 'G'),
}
if $ensure == present {
$enable = $startup ? {'automatic' => 'true', 'manual' => 'manual', default => 'false' }
service { 'puppeteermon':
ensure => $state,
enable => $enable,
provider => 'launchd',
require => Puppeteermon['/opt/puppeteermon/puppeteermon']
}
}
} else {
# Non-configurable class parameters
$basedir = '/opt/puppeteermon'
$os_source = regsubst($source, '<%= ::osfamily %>', 'linux', 'G')
$puppeteer_os_source = regsubst($profile::ct::puppeteer::source, '<%= ::osfamily %>', 'linux', 'G')
$puppeteer_fetch_source = regsubst($puppeteer_os_source, '<%= version %>', $profile::ct::puppeteer::version, 'G')
$puppeteer_recovery_source = regsubst($puppeteer_os_source, '<%= version %>', 'recovery', 'G')
profile::ct::puppeteer::config_new { \"${profile::ct::puppeteer::basedir}/puppeteer.yaml\":
ensure => $ensure,
compass_master_url => $profile::ct::puppeteer::compass_master_url,
compass_polling_interval => $profile::ct::puppeteer::compass_polling_interval,
runinterval => $profile::ct::puppeteer::runinterval,
last_run_summary => $profile::ct::puppeteer::last_run_summary,
splay => $profile::ct::puppeteer::splay,
version => $profile::ct::puppeteer::version,
agent_config_platform => $profile::ct::puppeteer::agent_config_platform,
}
-> profile::ct::puppeteermon::config_new { \"${basedir}/puppeteermon.yaml\":
ensure => $ensure,
cooldown => $cooldown,
fetch_url => $puppeteer_fetch_source,
recovery_url => $puppeteer_recovery_source,
download_dir => \"${profile::ct::puppeteer::basedir}/stage\",
command => \"${profile::ct::puppeteer::basedir}/running/puppeteer\",
min_exec_time => $min_exec_time
}
-> puppeteermon { '/opt/puppeteermon/puppeteermon':
ensure => $ensure,
version => $version,
source => regsubst($os_source, '<%= version %>', $version, 'G'),
}
if $ensure == present {
$enable = $startup ? {'automatic' => 'true', 'manual' => 'manual', default => 'false' }
service { 'puppeteermon':
ensure => $state,
enable => $enable,
provider => 'systemd',
require => Puppeteermon['/opt/puppeteermon/puppeteermon']
}
}
}
}
";
// result will be an iterator over tuples containing the start and end indices for each match in the string
let result = regex.captures_iter(string);
for mat in result {
println!("{:?}", mat);
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Rust, please visit: https://docs.rs/regex/latest/regex/