UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

86 lines • 3.81 kB
// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. ========= // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // ========= Copyright 2026 @ Strukto.AI All Rights Reserved. ========= import {} from "../../../../commands/spec/parser.js"; import { ambiguousOptionError, missingValueError, unexpectedValueError, unknownOptionError, } from "../../../../commands/spec/usage.js"; import { strerrorOf } from "../../../../errors/fs.js"; import { classify } from "../../../../errors/index.js"; import { decodeText } from "../../../../shell/bytes.js"; import { PathSpec } from "../../../../types.js"; import { result } from "../shared.js"; // attr 2.5.2's usage blocks, which follow getopt's one-line refusal and // end every usage error (exit 2) with the older backquote hint. export const GETFATTR_USAGE = 'Usage: getfattr [-hRLP] [-n name|-d] [-e en] [-m pattern] path...\n' + "Try `getfattr --help' for more information.\n"; export const SETFATTR_USAGE = 'Usage: setfattr {-n name} [-v value] [-h] file...\n' + ' setfattr {-x name} [-h] file...\n' + "Try `setfattr --help' for more information.\n"; /** * The usage error attr prints for a line getopt refused, if any: getopt's * own line (`invalid option -- 'Z'`, `option requires an argument -- * 'n'`) and then attr's usage block, exit 2. Mirrors Python's * `attr_usage_refusal`. */ export function attrUsageRefusal(cmd, parsed, usage) { let message = null; const ambiguous = parsed.ambiguousOptions[0]; const invalid = parsed.invalidOptions[0]; const needsValue = parsed.needsValueOptions[0]; if (ambiguous !== undefined && (invalid === undefined || parsed.optionErrorKinds[0] === 'ambiguous')) { ; [message] = ambiguousOptionError(cmd, ...ambiguous); } else if (invalid !== undefined) { ; [message] = parsed.optionErrorKinds[0] === 'unexpected_value' ? unexpectedValueError(cmd, invalid) : unknownOptionError(cmd, invalid); } else if (needsValue !== undefined) { ; [message] = missingValueError(cmd, needsValue); } if (message === null) return null; const line = decodeText(message).split('\n', 1)[0] ?? ''; return result(cmd, { exitCode: 2, stderr: `${line}\n${usage}` }); } /** * The phrase attr prints for a failed attribute call: "No such * attribute" for one that is not set, whatever the platform calls it, * the C library's wording for any other condition, and a service's own * words for its refusal. Mirrors Python's `attr_error`. */ export function attrError(err) { return classify(err) === 'NO_XATTR' ? 'No such attribute' : strerrorOf(err); } /** * The line's file operands, resolved against the session's cwd, each * keeping the spelling it was typed with for the header and messages. * Mirrors Python's `attr_operands`. */ export function attrOperands(parsed) { const typed = parsed.rawOperands; return parsed.args.map(([path], i) => { const spec = PathSpec.fromStrPath(path); return new PathSpec({ virtual: spec.virtual, directory: spec.directory, vfsPath: spec.vfsPath, rawPath: typed[i]?.[0] ?? path, }); }); } //# sourceMappingURL=xattr.js.map