rebased PR and changed according to comments:
 - argparse validation of passed path argument
 - return -1 instead or errno error code, and print error message
 - argparse --help prints default value for path


In contrast to comment, new argparse validation checks for valid file or
folder, since I see no need to restrict the argument to folders only, i.e.
it is valid to ask for the workspace root for a given file within that
workspace.



On Mon, Mar 17, 2014 at 9:27 PM, Dirk Thomas <notifications@github.com>wrote:

> In bin/catkin_find_workspace_root:
>
> > +
> > +# find the import relatively if available to work before installing catkin or overlaying installed version
> > +if os.path.exists(os.path.join(os.path.dirname(__file__), '..', 'python', 'catkin', '__init__.py')):
> > +    sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'python'))
> > +from catkin.workspace import get_containing_workspace_root
> > +
> > +
> > +def parse_args(args=sys.argv[1:]):
> > +    parser = argparse.ArgumentParser(
> description='returns the workspace root folder for the passed argument path, or else for the current path')
> > +    parser.add_argument('path', nargs='?', help='Any path from where to search')
> > +    return parser.parse_args(args=args)
> > +
> > +
> > +def main():
> > +    args = parse_args()
> > +    result = get_containing_workspace_root(os.path.abspath(args.path or '.'))
>
> Please make . the default value in argparse so that -help can print the
> default value as well.
>
> --
> Reply to this email directly or view it on GitHub<https://github.com/ros/catkin/pull/603/files#r10677084>
> .
>