hautils

[hare] Set of POSIX utilities
Log | Files | Refs | README | LICENSE

dirname.ha (397B)


      1 use fmt;
      2 use fs;
      3 use getopt;
      4 use io;
      5 use main;
      6 use os;
      7 use path;
      8 
      9 export fn utilmain() (main::error | void) = {
     10 	const help: []getopt::help = [
     11 		"return the directory portion of a pathname",
     12 		"<path>",
     13 	];
     14 	const cmd = getopt::parse(os::args, help...);
     15 	defer getopt::finish(&cmd);
     16 	if (len(cmd.args) != 1) {
     17 		main::usage(help);
     18 	};
     19 	fmt::println(path::dirname(cmd.args[0]))?;
     20 	return void;
     21 };