Skip to content

Commit

Permalink
Add a version command + bump up stash version.
Browse files Browse the repository at this point in the history
  • Loading branch information
rorokimdim committed Jan 2, 2021
1 parent a335526 commit 5c252ad
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 12 deletions.
7 changes: 3 additions & 4 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@ import qualified DB
import qualified IOUtils
import qualified TextTransform
import qualified BabashkaPod as BPod
import qualified Version

import Types

appVersion :: String
appVersion = "0.2.0"

type SelectedIndex = Int
type ResourceName = String
data DirectionKey = UP | DOWN | LEFT | RIGHT deriving (Show)
Expand Down Expand Up @@ -926,6 +924,7 @@ processCommand (C.ImportCommand dbPath format) = do
case format of
C.ImportFormatMarkdown -> importText MarkdownText
C.ImportFormatOrg -> importText OrgText
processCommand C.VersionCommand = putStrLn Version.appVersion

setUpLogging :: IO ()
setUpLogging = do
Expand All @@ -950,6 +949,6 @@ main = do
opts = O.info
(parser O.<**> O.helper)
(O.fullDesc <> O.progDesc "stash [create | browse | dump | backup | import]" <> O.header
("Stash " <> appVersion <> " https://github.com/rorokimdim/stash")
("Stash " <> Version.appVersion <> " https://github.com/rorokimdim/stash")
)
preferences = O.prefs (O.showHelpOnError <> O.showHelpOnEmpty)
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ get_next_version() {
}

maybe_update_version() {
sed -i.backup "s/appVersion =.*/appVersion = \"$(get_next_version)\"/" app/Main.hs
rm -rf app/Main.hs.backup
sed -i.backup "s/appVersion =.*/appVersion = \"$(get_next_version)\"/" src/Version.hs
rm -rf src/Version.hs.backup
}

check_stack
Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: stash
version: 0.2.0
version: 0.3.0
github: "rorokimdim/stash"
license: BSD3
author: "Amit Shrestha"
Expand Down
5 changes: 5 additions & 0 deletions scripting-examples/babashka/stash.clj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
"stash-path" stash-file-path
"create-stash-if-missing" true})))

(defn stash-version
"Gets version of stash command."
[]
(stash/version))

(defn stash-nodes
"Gets all nodes stored in stash.
Expand Down
5 changes: 5 additions & 0 deletions scripting-examples/python/stash.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ def stash_init():
'create-stash-if-missing': True})


def stash_version():
"""Gets version of stash command."""
return stash_invoke('version')


def stash_nodes(parent_id=0):
"""Gets all nodes stored in stash.
Expand Down
12 changes: 12 additions & 0 deletions src/BabashkaPod.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import qualified Data.Text as T

import qualified DB
import qualified IOUtils
import qualified Version

import Types

Expand Down Expand Up @@ -289,6 +290,14 @@ handleDeleteRequest s rid args = do
, ("status", BE.BList [BE.BString "done"])
]

handleVersionRequest :: PodState -> PodRequestId -> Args -> IO (PodState, BE.BEncode)
handleVersionRequest s rid args = do
continueState s $ BE.BDict $ Map.fromList
[ ("id" , BE.BString rid)
, ("value" , BE.BString (encode Version.appVersion))
, ("status", BE.BList [BE.BString "done"])
]

handleInvokeRequest :: PodState -> InvokeRequest -> IO (PodState, BE.BEncode)
handleInvokeRequest s (InvokeRequest "pod.rorokimdim.stash/init" rid args) =
handleInitRequest s rid args
Expand Down Expand Up @@ -317,6 +326,8 @@ handleInvokeRequest s (InvokeRequest "pod.rorokimdim.stash/update" rid args) =
handleUpdateRequest s rid args
handleInvokeRequest s (InvokeRequest "pod.rorokimdim.stash/delete" rid args) =
handleDeleteRequest s rid args
handleInvokeRequest s (InvokeRequest "pod.rorokimdim.stash/version" rid args) =
handleVersionRequest s rid args
handleInvokeRequest s (InvokeRequest var rid _) =
continueState s $ constructBencodeError rid "Invalid invoke request" (BE.BString var)

Expand Down Expand Up @@ -361,6 +372,7 @@ podDescription rid = BE.BDict $ Map.fromList
, BE.BDict $ Map.fromList [("name", BE.BString "rename")]
, BE.BDict $ Map.fromList [("name", BE.BString "update")]
, BE.BDict $ Map.fromList [("name", BE.BString "delete")]
, BE.BDict $ Map.fromList [("name", BE.BString "version")]
]
)
]
Expand Down
15 changes: 10 additions & 5 deletions src/CommandParsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ data Command = DumpCommand FilePath DumpFormat
| BackupCommand FilePath
| CreateCommand FilePath
| ImportCommand FilePath ImportFormat
| VersionCommand

browseFormatReader :: O.ReadM BrowseFormat
browseFormatReader = O.eitherReader f
Expand Down Expand Up @@ -140,6 +141,9 @@ backupCommandParser = BackupCommand <$> stashFilePathArgument
createCommandParser :: O.Parser Command
createCommandParser = CreateCommand <$> stashFilePathArgument

versionCommandParser :: O.Parser Command
versionCommandParser = pure VersionCommand

type CommandAlias = String
type CommandDescription = String
buildParser
Expand All @@ -155,9 +159,10 @@ buildParser xs = concat $ do

commands :: [O.Mod O.CommandFields Command]
commands = buildParser
[ (["create"], createCommandParser, "Create stash")
, (["browse"], browseCommandParser, "Browse stash")
, (["dump"] , dumpCommandParser , "Dump stash")
, (["backup"], backupCommandParser, "Backup stash")
, (["import"], importCommandParser, "Import text into stash from stdin")
[ (["create"] , createCommandParser , "Create stash")
, (["browse"] , browseCommandParser , "Browse stash")
, (["dump"] , dumpCommandParser , "Dump stash")
, (["backup"] , backupCommandParser , "Backup stash")
, (["import"] , importCommandParser , "Import text into stash from stdin")
, (["version"], versionCommandParser, "Print stash version")
]
7 changes: 7 additions & 0 deletions src/Version.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Version
( appVersion
)
where

appVersion :: String
appVersion = "0.3.0"

0 comments on commit 5c252ad

Please sign in to comment.