Skip to content

Commit

Permalink
Merge pull request #991 from ninoseki/renew-thor-desc
Browse files Browse the repository at this point in the history
refactor: renew Thor descriptions
  • Loading branch information
ninoseki authored Jan 7, 2024
2 parents 17814a8 + ecbeb8f commit a7b7c53
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 40 deletions.
60 changes: 36 additions & 24 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,25 @@ Options:
```bash
$ mihari alert
Commands:
mihari alert create [PATH] # Create an alert
mihari alert delete [ID] # Delete an alert
mihari alert get [ID] # Get an alert
mihari alert help [COMMAND] # Describe subcommands or one specific subcommand
mihari alert list [QUERY] # List/search alerts
mihari alert create PATH # Create an alert
mihari alert delete ID # Delete an alert
mihari alert get ID # Get an alert
mihari alert help [COMMAND] # Describe subcommands or one specific subcommand
mihari alert list QUERY # List/search alerts
mihari alert list-transform QUERY -t, --template=TEMPLATE # List/search alerts with transformation
```

### `mihari artifact`

```bash
$ mihari artifact
Commands:
mihari artifact delete [ID] # Delete an artifact
mihari artifact enrich [ID] # Enrich an artifact
mihari artifact get [ID] # Get an artifact
mihari artifact help [COMMAND] # Describe subcommands or one specific subcommand
mihari artifact list [QUERY] # List/search artifact
mihari artifact delete ID # Delete an artifact
mihari artifact enrich ID # Enrich an artifact
mihari artifact get ID # Get an artifact
mihari artifact help [COMMAND] # Describe subcommands or one specific subcommand
mihari artifact list QUERY # List/search artifacts
mihari artifact list-transform QUERY -t, --template=TEMPLATE # List/search artifacts with transformation
```

!!! note
Expand All @@ -65,13 +67,14 @@ See [Database](./emitters/database.md) for detailed database configuration.
```bash
$ mihari rule
Commands:
mihari rule delete [ID] # Delete a rule
mihari rule get [ID] # Get a rule
mihari rule help [COMMAND] # Describe subcommands or one specific subcommand
mihari rule init [PATH] # Initialize a new rule file
mihari rule list [QUERY] # List/search rules
mihari rule search [PATH_OR_ID] # Search by a rule
mihari rule validate [PATH] # Validate a rule file
mihari rule delete ID # Delete a rule
mihari rule get ID # Get a rule
mihari rule help [COMMAND] # Describe subcommands or one specific subcommand
mihari rule init PATH # Initialize a new rule file
mihari rule list QUERY # List/search rules
mihari rule list-transform QUERY -t, --template=TEMPLATE # List/search rules with transformation
mihari rule search PATH_OR_ID # Search by a rule
mihari rule validate PATH # Validate a rule file
```

### `mihari search`
Expand Down Expand Up @@ -100,9 +103,10 @@ mihari search -f /path/to/rule.yml
```bash
$ mihari tag
Commands:
mihari tag delete [ID] # Delete a tag
mihari tag help [COMMAND] # Describe subcommands or one specific subcommand
mihari tag list # List/search tags
mihari tag delete ID # Delete a tag
mihari tag help [COMMAND] # Describe subcommands or one specific subcommand
mihari tag list QUERY # List/search tags
mihari tag list-transform QUERY -t, --template=TEMPLATE # List/search tags with transformation
```

### `mihari web`
Expand Down Expand Up @@ -215,7 +219,15 @@ mihari artifact list-transform -t test.json.jbuilder

A template can use the following attributes.

- `results`: a list of search results (= `Array[Mihari::Models::Rule]`, `Array[Mihari::Models::Alert]`, `Array[Mihari::Models::Artifact]` or `Array[Mihari::Models::Tag]`)
- `total`: a total number of search results
- `page_size` a page size
- `current_page` a current page number
| Key | Type | Desc. |
| -------------- | -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------- |
| `results` | `Array[Mihari::Models::Rule]`, `Array[Mihari::Models::Alert]`, `Array[Mihari::Models::Artifact]` or `Array[Mihari::Models::Tag]` | A list of search results |
| `total` | Integer | A total number of search results |
| `page_size` | Integer | A page size |
| `current_page` | Integer | A current page number |

!!! warning

With great power comes great responsibility.

Jbuilder can execute anything with the same privilege Mihari has. Do not use untrusted template.
8 changes: 4 additions & 4 deletions lib/mihari/commands/alert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def _search(q, page: 1, limit: 10)
end
end

desc "create [PATH]", "Create an alert"
desc "create PATH", "Create an alert"
around :with_db_connection
#
# @param [String] path
Expand All @@ -46,7 +46,7 @@ def create(path)
puts JSON.pretty_generate(data.as_json)
end

desc "list [QUERY]", "List/search alerts"
desc "list QUERY", "List/search alerts"
around :with_db_connection
method_option :page, type: :numeric, default: 1
method_option :limit, type: :numeric, default: 10
Expand Down Expand Up @@ -86,7 +86,7 @@ def list_transform(q = "")
)
end

desc "get [ID]", "Get an alert"
desc "get ID", "Get an alert"
around :with_db_connection
#
# @param [Integer] id
Expand All @@ -97,7 +97,7 @@ def get(id)
puts JSON.pretty_generate(data.as_json)
end

desc "delete [ID]", "Delete an alert"
desc "delete ID", "Delete an alert"
around :with_db_connection
#
# @param [Integer] id
Expand Down
8 changes: 4 additions & 4 deletions lib/mihari/commands/artifact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def _search(q, page: 1, limit: 10)
end
end

desc "list [QUERY]", "List/search artifacts"
desc "list QUERY", "List/search artifacts"
around :with_db_connection
method_option :page, type: :numeric, default: 1
method_option :limit, type: :numeric, default: 10
Expand Down Expand Up @@ -65,7 +65,7 @@ def list_transform(q = "")
)
end

desc "get [ID]", "Get an artifact"
desc "get ID", "Get an artifact"
around :with_db_connection
#
# @param [Integer] id
Expand All @@ -76,7 +76,7 @@ def get(id)
puts JSON.pretty_generate(data.as_json)
end

desc "enrich [ID]", "Enrich an artifact"
desc "enrich ID", "Enrich an artifact"
around :with_db_connection
#
# @param [Integer] id
Expand All @@ -85,7 +85,7 @@ def enrich(id)
Services::ArtifactEnricher.result(id).value!
end

desc "delete [ID]", "Delete an artifact"
desc "delete ID", "Delete an artifact"
around :with_db_connection
#
# @param [Integer] id
Expand Down
10 changes: 5 additions & 5 deletions lib/mihari/commands/rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def _search(q, page: 1, limit: 10)
end
end

desc "validate [PATH]", "Validate a rule file"
desc "validate PATH", "Validate a rule file"
#
# Validate format of a rule
#
Expand All @@ -37,7 +37,7 @@ def validate(path)
puts rule.data.to_yaml
end

desc "init [PATH]", "Initialize a new rule file"
desc "init PATH", "Initialize a new rule file"
#
# Initialize a new rule file
#
Expand All @@ -50,7 +50,7 @@ def init(path = "./rule.yml")
Services::RuleInitializer.call(path)
end

desc "list [QUERY]", "List/search rules"
desc "list QUERY", "List/search rules"
around :with_db_connection
method_option :page, type: :numeric, default: 1
method_option :limit, type: :numeric, default: 10
Expand Down Expand Up @@ -90,15 +90,15 @@ def list_transform(q = "")
)
end

desc "get [ID]", "Get a rule"
desc "get ID", "Get a rule"
around :with_db_connection
def get(id)
value = Services::RuleGetter.result(id).value!
data = Entities::Rule.represent(value)
puts JSON.pretty_generate(data.as_json)
end

desc "delete [ID]", "Delete a rule"
desc "delete ID", "Delete a rule"
around :with_db_connection
#
# @param [String] id
Expand Down
2 changes: 1 addition & 1 deletion lib/mihari/commands/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def included(thor)
thor.class_eval do
include Concerns::DatabaseConnectable

desc "search [PATH_OR_ID]", "Search by a rule"
desc "search PATH_OR_ID", "Search by a rule"
around :with_db_connection
method_option :force_overwrite, type: :boolean, default: false, aliases: "-f",
desc: "Force overwriting a rule"
Expand Down
4 changes: 2 additions & 2 deletions lib/mihari/commands/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def _search(q, page: 1, limit: 10)
end
end

desc "list", "List/search tags"
desc "list QUERY", "List/search tags"
around :with_db_connection
method_option :page, type: :numeric, default: 1
method_option :limit, type: :numeric, default: 10
Expand Down Expand Up @@ -65,7 +65,7 @@ def list_transform(q = "")
)
end

desc "delete [ID]", "Delete a tag"
desc "delete ID", "Delete a tag"
around :with_db_connection
#
# @param [Integer] id
Expand Down

0 comments on commit a7b7c53

Please sign in to comment.