本文整理汇总了TypeScript中ssh-config.parse函数的典型用法代码示例。如果您正苦于以下问题:TypeScript parse函数的具体用法?TypeScript parse怎么用?TypeScript parse使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should stringify with config4 file', async () => {
const config4 = await readFile(path.resolve(__dirname, 'fixtures/ssh-config/config4'), { encoding: 'utf8' });
const conf = SSHConfig.parse(config4);
ensureHostAndKeyPath(conf, { host: 'bar' }, '/id_rsa');
const s = config4.split('\n');
s[s.length - 2] = ' IdentityFile /id_rsa';
expect(SSHConfig.stringify(conf)).toEqual(s.join('\n'));
});
示例2: ensureHostSection
function ensureHostSection(conf: SSHConfig.SSHConfig, host: string): SSHConfig.ConfigHostDirective {
let section = findHostSection(conf, host);
if (!section) {
conf.push(SSHConfig.parse(`\nHost ${host}\n`)[0]);
section = findHostSection(conf, host);
}
if (!section) {
throw new Error(`Could not find/insert section for host: ${host}`);
}
return section;
}
示例3: ensureSectionLine
function ensureSectionLine(section: SSHConfig.ConfigHostDirective, key: string, value: string): void {
const found = section.config.some(line => {
if (isDirective(line)) {
if (line.param === key) {
line.value = value;
return true;
}
}
return false;
});
if (!found) {
section.config = section.config.concat(SSHConfig.parse(`${key} ${value}\n`));
}
}
示例4: loadFromPath
export async function loadFromPath(p: string): Promise<SSHConfig.SSHConfig> {
const s = await fileToString(p);
return SSHConfig.parse(s);
}