@@ 13,8 13,27 @@ use os;
use path;
use shlex;
use unix::tty;
+use strings;
export fn main() void = {
+ const cmd = getopt::parse(os::args,
+ "hissh import",
+ ('c', "comment", "add or overwrite comment prior importing"),
+ );
+ defer getopt::finish(&cmd);
+
+ let comment: (str | void) = void;
+ for (let i = 0z; i < len(cmd.opts); i += 1) {
+ const opt = cmd.opts[i];
+ switch (opt.0) {
+ case 'c' =>
+ comment = strings::dup(opt.1);
+ case =>
+ fmt::fatalf("unknown option");
+ };
+ };
+
+
const key = match (ssh::decodesshprivate(os::stdin)) {
case let key: ssh::sshprivkey =>
yield key;
@@ 34,6 53,14 @@ export fn main() void = {
};
defer ssh::key_free(privkey);
+ match (comment) {
+ case void =>
+ yield;
+ case let c: str =>
+ free(privkey.comment);
+ privkey.comment = c;
+ };
+
let buf = memio::dynamic();
defer io::close(&buf)!;
fmt::fprintf(&buf, "add proto=ssh type={} pkey='", ssh::keytype(privkey))!;