Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #6264 Add --no-init flag to stack new #6265

Merged
merged 1 commit into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Behavior changes:

Other enhancements:

* Add flag `--no-init` to Stack's `new` command to skip the initialisation of
the newly-created project for use with Stack.

Bug fixes:

## v2.13.1 - 2023-09-29
Expand Down
43 changes: 30 additions & 13 deletions doc/new_command.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@
# The `stack new` command

~~~text
stack new PACKAGE_NAME [--bare] [TEMPLATE_NAME] [-p|--param KEY:VALUE] [DIR(S)]
[--omit-packages] [--force] [--ignore-subdirs]
stack new PACKAGE_NAME [--bare] [--[no-]init] [TEMPLATE_NAME]
[-p|--param KEY:VALUE] [DIR(S)] [--omit-packages] [--force]
[--ignore-subdirs]
~~~

`stack new` creates a new Stack project for a package using a project template.
`stack new` creates a new project using a project template.

The project is created in a new directory named after the package, unless the
`--bare` flag is passed, in which case the project is created in the current
directory.
By default:

* the project is created in a new directory named after the package. Pass the
`--bare` flag to create the project in the current directory; and

* the project is initialised for use with Stack. Pass the `--no-init` flag to
skip such initialisation.

The `--param <key>:<value>` option specifies a key-value pair to populate a key
in a template. The option can be specified multiple times.

The arguments specifying directories and the `--ignore-subdirs`, `--force` and
`--omit-packages` flags are as for the [`stack init` command](init_command.md).
These arguments are ignored if the `--no-init` flag is passed.

## Project templates

Expand Down Expand Up @@ -45,49 +51,60 @@ the default project template name is `new-template`.
## Examples

Create a project for package `my-project` in new directory `my-project` with the
default project template file:
default project template file and initialise it for use with Stack:

~~~text
stack new my-project
~~~

Create a project for package `my-package` in the current directory with the
default project template file:
default project template file and initialise it for use with Stack:

~~~text
stack new my-package --bare
~~~

Create a project with the `rio` project template at the default repository:
Create a project with the `rio` project template at the default repository and
initialise it for use with Stack:

~~~text
stack new my-project rio
~~~

Create a project with the `mysql` project template provided by the
`yesodweb/stack-templates` repository on GitHub:
`yesodweb/stack-templates` repository on GitHub and initialise it for use with
Stack:

~~~text
stack new my-project yesodweb/mysql
~~~

Create a project with the `my-template` project template provided by the
`username/stack-templates` repository on Bitbucket:
`username/stack-templates` repository on Bitbucket and initialise it for use
with Stack:

~~~text
stack new my-project bitbucket:username/my-template
~~~

Create a project with the `my-template.hsfiles` project template file at
`https://example.com`:
`https://example.com` and initialise it for use with Stack:

~~~text
stack new my-project https://example.com/my-template
~~~

Create a project with the local project template file
`<path_to_template>/my-template.hsfiles`:
`<path_to_template>/my-template.hsfiles` and initialise it for use with Stack:

~~~text
stack new my-project <path_to_template_file>/my-template
~~~

Create a project with the `simple` project template file at the default
repository (which does not use Hpack and a `package.yaml` file) and do not
initialise it for use with Stack (`stack init` could be used subsequently):

~~~text
stack new my-project --no-init simple
~~~
12 changes: 7 additions & 5 deletions src/Stack/New.hs
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,15 @@ instance Exception NewPrettyException
-- than those applicable also to the @stack init@ command).
data NewOpts = NewOpts
{ newOptsProjectName :: PackageName
-- ^ Name of the project to create.
-- ^ Name of the project to create.
, newOptsCreateBare :: Bool
-- ^ Whether to create the project without a directory.
-- ^ Whether to create the project without a directory.
, newOptsInit :: Bool
-- ^ Whether to initialise the project for use with Stack.
, newOptsTemplate :: Maybe TemplateName
-- ^ Name of the template to use.
-- ^ Name of the template to use.
, newOptsNonceParams :: Map Text Text
-- ^ Nonce parameters specified just for this invocation.
-- ^ Nonce parameters specified just for this invocation.
}

-- | Function underlying the @stack new@ command. Create a project directory
Expand All @@ -231,7 +233,7 @@ newCmd (newOpts, initOpts) =
withGlobalProject $ withConfig YesReexec $ do
dir <- new newOpts (forceOverwrite initOpts)
exists <- doesFileExist $ dir </> stackDotYaml
when (forceOverwrite initOpts || not exists) $ do
when (newOptsInit newOpts && (forceOverwrite initOpts || not exists)) $ do
go <- view globalOptsL
initProject dir initOpts (globalResolver go)

Expand Down
7 changes: 6 additions & 1 deletion src/Stack/Options/NewParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module Stack.Options.NewParser

import qualified Data.Map.Strict as M
import Options.Applicative
( Parser, help, long, metavar, short, switch )
( Parser, help, idm, long, metavar, short, switch )
import Options.Applicative.Builder.Extra ( boolFlags )
import Stack.Init ( InitOpts )
import Stack.New ( NewOpts (..) )
import Stack.Options.InitParser ( initOptsParser )
Expand All @@ -28,6 +29,10 @@ newOptsParser = (,) <$> newOpts <*> initOptsParser
( long "bare"
<> help "Do not create a subdirectory for the project."
)
<*> boolFlags True
"init"
"the initialisation of the project for use with Stack."
idm
<*> optional (templateNameArgument
( metavar "TEMPLATE_NAME"
<> help "Name of a template - can take the form\
Expand Down