fpco / stackage-cli

MIT License
28 stars 4 forks source link

stackage-init target #4

Closed chrisdone closed 9 years ago

chrisdone commented 9 years ago

The executable target should be stackage-init. This is one of the built-in plugins that come with the project and serves as a good demonstration.

Setup a cabal.config file in the current directory by either receiving a snapshot hash or alias as argument, or by prompting the user to enter one. It may default to lts with a "RET to choose default". Or optionally be like Enter snapshot (tls/nightly/<hash>):, so that one can just grab whatever lts or nightly is current. Maybe also support --lts or --nightly flag. There's a bit of freedom here, but think: convenient. Think of users first coming to hackage and also experts.

DanBurton commented 9 years ago

Bikeshedding: rather than setup, I think init is more common terminology for such an operation. (e.g. git, yesod, cabal).

If a cabal.config file already exists, what do you think this operation should do?

chrisdone commented 9 years ago

I wasn't committed to the setup name, init does make sense, let's go with that.

chrisdone commented 9 years ago

If it already exists we could ignore it which would make the command somewhat idempotent a la cabal.

DanBurton commented 9 years ago

@chrisdone I've added stackage-init, with a sketch of the implementation. It doesn't make it past the parser, though. If you have a spare moment, take a look and perhaps you can help me figure out why.

https://github.com/fpco/stackage-cli/blob/master/stackage-init/main/Main.hs

chrisdone commented 9 years ago

What does it do? No output?

DanBurton commented 9 years ago

It outputs a "usage" message. main never got past the simpleOptions line, because optparse-applicative decided that the program was not invoked correctly. I've temporarily changed it to not use optparse-applicative, and it works as expected.

chrisdone commented 9 years ago

I fixed that problem. You should be able to complete this now unimpeded by the optparse stuff.

chrisdone commented 9 years ago

Current behaviour:

$ stackage --help
Run stackage commands

Usage: stackage [--help] [--version] [--summary] COMMAND
  Run stackage commands

Available options:
  --help                   Show this help text
  --version                Show version
  --summary                Show program summary

Available commands:
  stackage                 Upgrade stackage stuff
  stackage                 Upgrade stackage stuff
  stackage                 Upgrade stackage stuff
$ stackage init --help
Initializes cabal.config

Usage: stackage-init [--help] [--version] [--summary] [SNAPSHOT]
  Initializes cabal.config

Available options:
  --help                   Show this help text
  --version                Show version
  --summary                Show program summary
$ stackage init
$ stackage init
Warning: cabal.config already exists
No action taken
stackage: StackagePluginExitFailure 1

chrisdone commented 9 years ago
DanBurton commented 9 years ago

Now supports any string that correctly fits between http://stackage.org/ and /cabal.config. This includes:

stackage init         # client defaults this to lts
stackage init lts     # server currently defaults this to 2.0
stackage init nightly # server currently defaults this to 2015-04-02
stackage init lts/1   # server currently defaults this to 1.15
stackage init lts/1.14
stackage init nightly/2015-04-01
stackage init snapshot/any-named-snapshot
DanBurton commented 9 years ago

Should be ready to close.

chrisdone commented 9 years ago

Confirmed.

In future let's consider listing these things, as the regular user won't know what are the valid strings to put here.

3noch commented 9 years ago

@chrisdone Did your suggestion ever make it in? I was just struggling with that today: "What are valid snapshots?" Would be awesome to list them out somehow.