Skip to content

Commit

Permalink
Merge pull request #37 from pokanop/issue-22-update-cmd
Browse files Browse the repository at this point in the history
Add update command to root
  • Loading branch information
saheljalal committed Jan 16, 2022
2 parents f7f022d + 54c4f36 commit 238781a
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 43 deletions.
20 changes: 4 additions & 16 deletions LICENSE
@@ -1,21 +1,9 @@
MIT License

Copyright (c) 2019 Pokanop Apps
Copyright (c) 2022 Pokanop Apps LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8 changes: 4 additions & 4 deletions cmd/addcmd.go
Expand Up @@ -26,9 +26,9 @@ var addcmdCmd = &cobra.Command{
A key path is a '.' delimited string, e.g., "key.path" which represents
the alias which can be run as "key path" for the actual command provided.
This will create appropriate command scopes for all levels in
the provided key path. A command scope can a tree of sub commands
and substitutions.
This will create appropriate command scopes for all levels in the provided
key path. A command scope can contain a tree of sub commands and
substitutions.
A command's mode indicates how it will be executed. By default, nostromo
concatenates parent and child commands along the tree. There are 3 modes
Expand All @@ -46,7 +46,7 @@ You can set using -m or --mode when adding a command or globally using:
if len(args) > 1 {
name = args[1]
}
os.Exit(task.AddCommand(args[0], name, description, code, language, aliasOnly, mode))
os.Exit(task.AddCommand(args[0], name, description, code, language, aliasOnly, mode, false))
},
}

Expand Down
51 changes: 51 additions & 0 deletions cmd/update.go
@@ -0,0 +1,51 @@
package cmd

import (
"os"

"github.com/pokanop/nostromo/task"
"github.com/spf13/cobra"
)

// updateCmd represents the update command
var updateCmd = &cobra.Command{
Use: "update [key.path] [command] [options]",
Short: "Update a command in nostromo manifest",
Long: `Update a command in nostromo manifest for a given key path.
A key path is a '.' delimited string, e.g., "key.path" which represents
the alias which can be run as "key path" for the actual command provided.
This will update appropriate command scopes for all levels in the provided
key path. A command scope can contain a tree of sub commands and
substitutions.
A command's mode indicates how it will be executed. By default, nostromo
concatenates parent and child commands along the tree. There are 3 modes
available to commands:
concatenate Concatenate this command with subcommands exactly as defined
independent Execute this command with subcommands using ';' to separate
exclusive Execute this and only this command ignoring parent commands
You can set using -m or --mode when adding a command or globally using:
nostromo manifest set mode <mode>`,
Args: addCmdArgs,
Run: func(cmd *cobra.Command, args []string) {
var name string
if len(args) > 1 {
name = args[1]
}
os.Exit(task.AddCommand(args[0], name, description, code, language, aliasOnly, mode, true))
},
}

func init() {
rootCmd.AddCommand(updateCmd)

// Flags
updateCmd.Flags().StringVarP(&description, "description", "d", "", "Description of the command to update")
updateCmd.Flags().StringVarP(&code, "code", "c", "", "Code snippet to run for this command")
updateCmd.Flags().StringVarP(&language, "language", "l", "", "Language of code snippet (e.g., ruby, python, perl, js)")
updateCmd.Flags().BoolVarP(&aliasOnly, "alias-only", "a", false, "Add shell alias only, not a nostromo command")
updateCmd.Flags().StringVarP(&mode, "mode", "m", "", "Set the mode for the command (concatenate, independent, exclusive)")
}
20 changes: 0 additions & 20 deletions main.go
@@ -1,23 +1,3 @@
// Copyright © 2019 Sahel Jalal <sahel.jalal@icloud.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package main

import "github.com/pokanop/nostromo/cmd"
Expand Down
12 changes: 9 additions & 3 deletions task/task.go
@@ -1,6 +1,8 @@
package task

import (
"strings"

"github.com/pokanop/nostromo/config"
"github.com/pokanop/nostromo/log"
"github.com/pokanop/nostromo/model"
Expand All @@ -11,7 +13,6 @@ import (
"github.com/pokanop/nostromo/version"
"github.com/shivamMg/ppds/tree"
"github.com/spf13/cobra"
"strings"
)

var ver *version.Info
Expand Down Expand Up @@ -247,7 +248,7 @@ func AddInteractive() int {
}
log.Highlight("\nCreating command...\n")

return AddCommand(keypath, cmd, description, snippet, language, aliasOnly, mode)
return AddCommand(keypath, cmd, description, snippet, language, aliasOnly, mode, false)
}

log.Regularf("A key path is a dot '.' delimited path to where you want to add your command.\n")
Expand All @@ -267,14 +268,19 @@ func AddInteractive() int {
}

// AddCommand to the manifest
func AddCommand(keyPath, command, description, code, language string, aliasOnly bool, mode string) int {
func AddCommand(keyPath, command, description, code, language string, aliasOnly bool, mode string, update bool) int {
cfg := checkConfig()
if cfg == nil {
return -1
}

m := cfg.Manifest()

if update && m.Find(keyPath) == nil {
log.Error("no matching command found to update")
return -1
}

snippet := &model.Code{
Language: language,
Snippet: code,
Expand Down

0 comments on commit 238781a

Please sign in to comment.