diff --git a/app/Main.hs b/app/Main.hs
new file mode 100644
--- /dev/null
+++ b/app/Main.hs
@@ -0,0 +1,43 @@
+{-# LANGUAGE MultiWayIf #-}
+
+module Main where
+
+import Control.Monad
+import Control.Monad.Trans.Maybe
+import Data.Maybe
+import Hie.Locate
+import Hie.Yaml
+import System.Directory
+import System.Environment
+import System.FilePath.Posix
+
+main :: IO ()
+main = do
+  pwd <- getCurrentDirectory
+  name <- resolveName pwd
+  cfs <- runMaybeT $ case name of
+    "cabal" -> cabalPkgs pwd
+    _ -> stackYamlPkgs pwd
+  when (null cfs) $
+    error $
+      "No .cabal files found under"
+        <> pwd
+        <> "\n You may need to run stack build."
+  pkgs <- catMaybes <$> mapM (nestedPkg pwd) (concat cfs)
+  putStr <$> hieYaml name $ fmtPkgs name pkgs
+
+resolveName :: FilePath -> IO String
+resolveName pwd = do
+  args <- getArgs
+  files <- listDirectory pwd
+  let fileNames = map takeFileName files
+      name =
+        if
+            | "--cabal" `elem` args -> "cabal"
+            | "--stack" `elem` args -> "stack"
+            | "dist-newstyle" `elem` fileNames -> "cabal"
+            | ".stack-work" `elem` fileNames -> "stack"
+            | "cabal.project" `elem` fileNames -> "cabal"
+            | "stack.yaml" `elem` fileNames -> "stack"
+            | otherwise -> "cabal"
+  return name
diff --git a/implicit-hie.cabal b/implicit-hie.cabal
--- a/implicit-hie.cabal
+++ b/implicit-hie.cabal
@@ -7,7 +7,7 @@
 -- hash: b2b829a658e33ea328c725dea732391089d03ffd2a216d413a75d88aefa7c181
 
 name:               implicit-hie
-version:            0.1.2.2
+version:            0.1.2.3
 description:
   Auto generate a stack or cabal multi component hie.yaml file
 
@@ -57,6 +57,20 @@
     , filepattern   >=0.1
     , text          >=1.2
     , transformers  >=0.5
+    , yaml          >=0.5
+
+  default-language: Haskell2010
+
+executable gen-hie
+  main-is:          Main.hs
+  other-modules:    Paths_implicit_hie
+  autogen-modules:  Paths_implicit_hie
+  hs-source-dirs:   app
+  ghc-options:
+    -Wall -Wincomplete-record-updates -Wincomplete-uni-patterns
+    -fno-warn-unused-imports -fno-warn-unused-binds
+    -fno-warn-name-shadowing -fwarn-redundant-constraints -threaded
+    -rtsopts -with-rtsopts=-N
 
   build-depends:
       attoparsec
