本文整理匯總了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);
}