• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Command-line parsing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Command-line parsing


  • Subject: Command-line parsing
  • From: Fritz Anderson <email@hidden>
  • Date: Wed, 21 Jul 2010 09:54:21 -0500

I'm writing a Foundation tool that will take both options and pathname arguments.

If you use NSUserDefaults, you can handle key-value options (-threshold 17) pretty easily, but this has limitations. I don't see how it can be graceful for

* Two-hyphen options (chatty --verbose).
* Non-value options (ls -a).
* Single-item key-value options (chatty --verbose=3 -or- chatty -v3).
* Concatenated options (ls -al)

I also don't know what you do about "normal" arguments (ls -al /Users/fritza) without using NSUserDefaults _and_ running through [[NSProcessInfo processInfo] arguments] with at least a minimal state machine, which defeats the purpose.

Enough complaining. Correct me if I'm wrong.

I remember from 2001 or so that there was an open-source framework inherited from the OpenStep days, that included a helper for getopt(3) sorts of tasks, but for the life of me, I can't remember its name, and I don't know where it would be hosted or whether it would be compatible with today's Foundation framework.

Yes, iterating through [[NSProcessInfo processInfo] arguments] and parsing for myself is the ultimate option, but if it's a solved problem, why make all the mistakes again?

Google doesn't turn up much, beyond the NSUserDefaults trick. Any ideas?

	— F

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Command-line parsing
      • From: Carter Allen <email@hidden>
    • Re: Command-line parsing
      • From: Alastair Houghton <email@hidden>
  • Prev by Date: Knowing how a Text Editing Session ended
  • Next by Date: Re: Knowing how a Text Editing Session ended
  • Previous by thread: Re: Knowing how a Text Editing Session ended
  • Next by thread: Re: Command-line parsing
  • Index(es):
    • Date
    • Thread