claiss 1.1.3 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +125 -68
- data/lib/claiss/commands.rb +8 -9
- data/lib/claiss/version.rb +2 -2
- data/lib/claiss.rb +103 -212
- metadata +3 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 444c32b0586f427d677d4c6adc09d9f0843044e17bdca20bcf9743436b61b925
|
4
|
+
data.tar.gz: 40cc9ba8569e33ce34aab0f77d53e56fed7bbae7d5229fb01619d3850b74115a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9afca82efd4a0a3da21f403d1a2108ef6ef97d742874f9190688f4eec4e51c8bfed4a9a4cdeca469b1f2dc5e5472182f72ecccf94d14466ff7bf79b447414ea8
|
7
|
+
data.tar.gz: adf058a7d49f3b966c8e7e21e5670c8017f02e37606a380809f035ce1d49060059c847c03e5559ec43f96bd77dfccfce0fd2900c7707e909132977bf79df5c03
|
data/README.md
CHANGED
@@ -1,126 +1,183 @@
|
|
1
1
|
# CLAISS CLI Refactor Application Toolbox
|
2
2
|
|
3
|
-
|
3
|
+
[English](#english) | [Português](#português)
|
4
|
+
|
5
|
+
# English
|
6
|
+
|
7
|
+
**CLAISS** is a Ruby-based CLI application and toolbox designed to manage CLAISS Refactored applications and deployments. Please note that some features may have limited compatibility depending on the environment. Use with caution!
|
4
8
|
|
5
9
|
## Installation
|
6
10
|
|
7
11
|
Install the CLAISS gem by running the following command in your terminal:
|
8
12
|
|
9
|
-
|
13
|
+
´´´sh
|
10
14
|
$ gem install claiss
|
11
|
-
|
15
|
+
´´´
|
12
16
|
|
13
17
|
## Usage
|
14
18
|
|
19
|
+
### Version
|
20
|
+
|
21
|
+
To check the CLAISS version:
|
22
|
+
|
23
|
+
´´´sh
|
24
|
+
$ claiss version
|
25
|
+
´´´
|
26
|
+
|
27
|
+
or use the shortcuts:
|
28
|
+
|
29
|
+
´´´sh
|
30
|
+
$ claiss v
|
31
|
+
$ claiss -v
|
32
|
+
$ claiss --version
|
33
|
+
´´´
|
34
|
+
|
15
35
|
### Refactor
|
16
36
|
|
17
|
-
The `refactor` command allows you to rename and replace text terms within files and filenames in a specified directory. This command will refactor all exact occurrences of specified terms, including filenames.
|
37
|
+
The `refactor` command allows you to rename and replace text terms within files and filenames in a specified directory. This command will refactor all exact occurrences of specified terms, including filenames.
|
18
38
|
|
19
39
|
**Note:** The `refactor` command ignores the `.git/` and `node_modules/` directories to avoid modifying critical or third-party files.
|
20
40
|
|
21
41
|
Basic usage:
|
22
42
|
|
23
|
-
|
24
|
-
$ claiss refactor <
|
25
|
-
|
26
|
-
|
27
|
-
- `<path>`: Path to the directory to refactor (required)
|
28
|
-
- `<rules>`: Name of the rules file (without .json extension) (required)
|
29
|
-
- `--destination`: Destination path for refactored files (optional)
|
43
|
+
´´´sh
|
44
|
+
$ claiss refactor <project_path> <json_file>
|
45
|
+
´´´
|
30
46
|
|
31
|
-
|
47
|
+
Example:
|
32
48
|
|
33
|
-
|
34
|
-
$ claiss refactor
|
35
|
-
|
36
|
-
```
|
49
|
+
´´´sh
|
50
|
+
$ claiss refactor llama_index laiss_labs.json
|
51
|
+
´´´
|
37
52
|
|
38
53
|
#### Using a JSON Dictionary
|
39
54
|
|
40
|
-
You can create a JSON file that specifies the terms you want to refactor. This JSON file should be structured as a simple key-value pair object, where each key is the term to be replaced and the value is the replacement term.
|
55
|
+
You can create a JSON file that specifies the terms you want to refactor. This JSON file should be structured as a simple key-value pair object, where each key is the term to be replaced and the value is the replacement term.
|
41
56
|
|
42
|
-
|
57
|
+
Example `laiss_labs.json`:
|
43
58
|
|
44
|
-
|
45
|
-
|
46
|
-
```json
|
59
|
+
´´´json
|
47
60
|
{
|
48
|
-
"
|
49
|
-
"
|
50
|
-
"
|
61
|
+
"system pro": "system b2b",
|
62
|
+
"System Pro": "System B2b",
|
63
|
+
"System": "Laiss",
|
64
|
+
"system": "laiss"
|
51
65
|
}
|
52
|
-
|
66
|
+
´´´
|
53
67
|
|
54
|
-
|
68
|
+
**Important:** After refactoring, any empty directories left behind will be automatically removed to keep your project structure clean.
|
55
69
|
|
56
|
-
|
70
|
+
### Fix Ruby Permissions
|
57
71
|
|
58
|
-
|
72
|
+
The `fix_ruby_permissions` command adjusts file permissions for a Ruby or Rails project.
|
59
73
|
|
60
|
-
|
74
|
+
´´´sh
|
75
|
+
$ claiss fix_ruby_permissions <project_path>
|
76
|
+
´´´
|
61
77
|
|
62
|
-
|
78
|
+
## Future Features
|
63
79
|
|
64
|
-
|
80
|
+
We are continuously working to improve CLAISS and add new functionalities. Stay tuned for updates!
|
65
81
|
|
66
|
-
|
82
|
+
## Contributing
|
67
83
|
|
68
|
-
|
84
|
+
Bug reports and pull requests are welcome on GitHub at [https://github.com/JulioPapel/claiss](https://github.com/JulioPapel/claiss).
|
69
85
|
|
70
|
-
|
71
|
-
$ claiss fix_ruby_permissions [path]
|
72
|
-
```
|
86
|
+
## License
|
73
87
|
|
74
|
-
|
88
|
+
This gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
75
89
|
|
76
|
-
|
90
|
+
## Author
|
77
91
|
|
78
|
-
|
79
|
-
$ claiss fix_ruby_permissions
|
80
|
-
$ claiss fix_ruby_permissions path/to/ruby/project
|
81
|
-
```
|
92
|
+
Júlio Papel
|
82
93
|
|
83
|
-
|
94
|
+
---
|
84
95
|
|
85
|
-
|
96
|
+
# Português
|
86
97
|
|
87
|
-
|
98
|
+
**CLAISS** é uma aplicação CLI e caixa de ferramentas em Ruby projetada para gerenciar aplicações e implantações CLAISS Refactored. Por favor, note que algumas funcionalidades podem ter compatibilidade limitada dependendo do ambiente. Use com cuidado!
|
88
99
|
|
89
|
-
|
90
|
-
$ claiss generate_json [options]
|
91
|
-
```
|
100
|
+
## Instalação
|
92
101
|
|
93
|
-
|
94
|
-
- `--output`: Name of the output JSON file (default: rules)
|
95
|
-
- `--path`: Path to save the JSON file (default: ~/.claiss/)
|
102
|
+
Instale a gem CLAISS executando o seguinte comando no seu terminal:
|
96
103
|
|
97
|
-
|
104
|
+
´´´sh
|
105
|
+
$ gem install claiss
|
106
|
+
´´´
|
98
107
|
|
99
|
-
|
100
|
-
$ claiss generate_json
|
101
|
-
$ claiss generate_json --output my_custom_rules
|
102
|
-
$ claiss generate_json --path /custom/path/ --output my_rules
|
103
|
-
```
|
108
|
+
## Uso
|
104
109
|
|
105
|
-
|
110
|
+
### Versão
|
106
111
|
|
107
|
-
|
112
|
+
Para verificar a versão do CLAISS:
|
108
113
|
|
109
|
-
|
114
|
+
´´´sh
|
115
|
+
$ claiss version
|
116
|
+
´´´
|
110
117
|
|
111
|
-
|
112
|
-
2. Support for more complex refactoring rules
|
118
|
+
ou use os atalhos:
|
113
119
|
|
114
|
-
|
120
|
+
´´´sh
|
121
|
+
$ claiss v
|
122
|
+
$ claiss -v
|
123
|
+
$ claiss --version
|
124
|
+
´´´
|
115
125
|
|
116
|
-
|
126
|
+
### Refactor
|
117
127
|
|
118
|
-
|
128
|
+
O comando `refactor` permite que você renomeie e substitua termos de texto dentro de arquivos e nomes de arquivos em um diretório especificado. Este comando irá refatorar todas as ocorrências exatas dos termos especificados, incluindo nomes de arquivos.
|
119
129
|
|
120
|
-
|
130
|
+
**Nota:** O comando `refactor` ignora os diretórios `.git/` e `node_modules/` para evitar modificar arquivos críticos ou de terceiros.
|
121
131
|
|
122
|
-
|
132
|
+
Uso básico:
|
123
133
|
|
124
|
-
|
134
|
+
´´´sh
|
135
|
+
$ claiss refactor <caminho_do_projeto> <arquivo_json>
|
136
|
+
´´´
|
137
|
+
|
138
|
+
Exemplo:
|
139
|
+
|
140
|
+
´´´sh
|
141
|
+
$ claiss refactor llama_index laiss_labs.json
|
142
|
+
´´´
|
143
|
+
|
144
|
+
#### Usando um Dicionário JSON
|
145
|
+
|
146
|
+
Você pode criar um arquivo JSON que especifica os termos que deseja refatorar. Este arquivo JSON deve ser estruturado como um objeto de pares chave-valor simples, onde cada chave é o termo a ser substituído e o valor é o termo de substituição.
|
147
|
+
|
148
|
+
Exemplo `laiss_labs.json`:
|
149
|
+
|
150
|
+
´´´json
|
151
|
+
{
|
152
|
+
"system pro": "system b2b",
|
153
|
+
"System Pro": "System B2b",
|
154
|
+
"System": "Laiss",
|
155
|
+
"system": "laiss"
|
156
|
+
}
|
157
|
+
´´´
|
158
|
+
|
159
|
+
**Importante:** Após a refatoração, quaisquer diretórios vazios deixados para trás serão automaticamente removidos para manter a estrutura do seu projeto limpa.
|
160
|
+
|
161
|
+
### Fix Ruby Permissions
|
162
|
+
|
163
|
+
O comando `fix_ruby_permissions` ajusta as permissões de arquivos para um projeto Ruby ou Rails.
|
164
|
+
|
165
|
+
´´´sh
|
166
|
+
$ claiss fix_ruby_permissions <caminho_do_projeto>
|
167
|
+
´´´
|
168
|
+
|
169
|
+
## Recursos Futuros
|
170
|
+
|
171
|
+
Estamos continuamente trabalhando para melhorar o CLAISS e adicionar novas funcionalidades. Fique atento para atualizações!
|
172
|
+
|
173
|
+
## Contribuindo
|
174
|
+
|
175
|
+
Relatórios de bugs e pull requests são bem-vindos no GitHub em [https://github.com/JulioPapel/claiss](https://github.com/JulioPapel/claiss).
|
176
|
+
|
177
|
+
## Licença
|
178
|
+
|
179
|
+
Esta gem está disponível como código aberto sob os termos da [Licença MIT](https://opensource.org/licenses/MIT).
|
180
|
+
|
181
|
+
## Autor
|
125
182
|
|
126
183
|
Júlio Papel
|
data/lib/claiss/commands.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
module CLAISS
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
10
|
-
end
|
2
|
+
module Commands
|
3
|
+
extend Dry::CLI::Registry
|
4
|
+
|
5
|
+
register "version", Version, aliases: ["v", "-v", "--version"]
|
6
|
+
register "refactor", Refactor
|
7
|
+
register "fix_ruby_permissions", FixRubyPermissions
|
8
|
+
end
|
9
|
+
end
|
data/lib/claiss/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module CLAISS
|
2
|
-
|
3
|
-
|
2
|
+
VERSION = "1.1.4"
|
3
|
+
end
|
data/lib/claiss.rb
CHANGED
@@ -1,21 +1,9 @@
|
|
1
|
-
require "dry/cli"
|
2
1
|
require "bundler/setup"
|
3
|
-
require
|
4
|
-
require 'json'
|
2
|
+
require "dry/cli"
|
5
3
|
require "fileutils"
|
6
|
-
require
|
7
|
-
require 'parallel'
|
8
|
-
require 'ruby-progressbar'
|
4
|
+
require "json"
|
9
5
|
|
10
|
-
# CLAISS module provides CLI commands for refactoring and managing Ruby projects
|
11
6
|
module CLAISS
|
12
|
-
IGNORED_DIRECTORIES = [".git/", "node_modules/"]
|
13
|
-
DEFAULT_JSON_DIR = File.join(Dir.home, '.claiss')
|
14
|
-
|
15
|
-
# Initialize logger
|
16
|
-
LOGGER = Logger.new(STDOUT)
|
17
|
-
LOGGER.level = Logger::INFO # Set to Logger::DEBUG for more verbose output
|
18
|
-
|
19
7
|
class Error < StandardError; end
|
20
8
|
|
21
9
|
class Version < Dry::CLI::Command
|
@@ -27,230 +15,130 @@ module CLAISS
|
|
27
15
|
end
|
28
16
|
|
29
17
|
class Refactor < Dry::CLI::Command
|
30
|
-
desc "
|
31
|
-
|
32
|
-
argument :
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
example [
|
37
|
-
"path/to/project autokeras",
|
38
|
-
"path/to/project autokeras --destination path/to/output"
|
39
|
-
]
|
40
|
-
|
41
|
-
def call(path:, rules:, destination: nil, **)
|
42
|
-
origin_path = File.expand_path(path)
|
43
|
-
destination_path = destination ? File.expand_path(destination) : nil
|
44
|
-
|
45
|
-
json_file = File.join(DEFAULT_JSON_DIR, "#{rules}.json")
|
18
|
+
desc "Refactors terms and files on directories"
|
19
|
+
argument :path, type: :string, required: true, desc: "Relative path directory"
|
20
|
+
argument :json_file, type: :string, desc: "Provide a JSON file with replacement rules"
|
21
|
+
|
22
|
+
def call(path:, json_file: nil, **)
|
46
23
|
dict = load_dictionary(json_file)
|
47
|
-
|
48
|
-
files = get_files_to_process(origin_path)
|
49
|
-
process_files_in_parallel(files, dict, origin_path, destination_path)
|
50
|
-
remove_empty_directories(destination_path || origin_path)
|
51
|
-
|
52
|
-
puts "Done! Files have been refactored#{destination_path ? ' to the destination' : ' in place'}."
|
53
|
-
end
|
24
|
+
origin_path = File.expand_path(path)
|
54
25
|
|
55
|
-
|
26
|
+
process_files(origin_path, dict)
|
27
|
+
remove_empty_directories(origin_path)
|
56
28
|
|
57
|
-
|
58
|
-
Dir.glob(File.join(origin_path, '**', '*'), File::FNM_DOTMATCH).reject do |file_name|
|
59
|
-
File.directory?(file_name) || IGNORED_DIRECTORIES.any? { |dir| file_name.include?(dir) }
|
60
|
-
end
|
29
|
+
puts "Done! Files have been refactored in place."
|
61
30
|
end
|
62
31
|
|
63
|
-
|
64
|
-
progress_bar = ProgressBar.create(
|
65
|
-
total: files.size,
|
66
|
-
format: "%a %b\u{15E7}%i %p%% %t",
|
67
|
-
progress_mark: ' ',
|
68
|
-
remainder_mark: "\u{FF65}"
|
69
|
-
)
|
70
|
-
|
71
|
-
Parallel.each(files, in_threads: Parallel.processor_count) do |file_name|
|
72
|
-
refactor_file(file_name, dict, origin_path, destination_path)
|
73
|
-
progress_bar.increment
|
74
|
-
end
|
75
|
-
end
|
32
|
+
private
|
76
33
|
|
77
34
|
def load_dictionary(json_file)
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
35
|
+
if json_file
|
36
|
+
# Procura o arquivo no diretório atual e no ~/.claiss
|
37
|
+
possible_paths = [
|
38
|
+
json_file,
|
39
|
+
File.expand_path(json_file),
|
40
|
+
File.expand_path("~/.claiss/#{json_file}"),
|
41
|
+
]
|
42
|
+
|
43
|
+
found_file = possible_paths.find { |path| File.exist?(path) }
|
44
|
+
|
45
|
+
if found_file
|
46
|
+
begin
|
47
|
+
dict = JSON.parse(File.read(found_file))
|
48
|
+
puts "Oba! Encontrei o arquivo em: #{found_file}"
|
49
|
+
return dict
|
50
|
+
rescue JSON::ParserError => e
|
51
|
+
puts "Ops! O arquivo JSON não está no formato correto. Erro: #{e.message}"
|
52
|
+
end
|
95
53
|
else
|
96
|
-
|
54
|
+
puts "Hmm, não consegui encontrar o arquivo. Procurei nesses lugares:"
|
55
|
+
possible_paths.each { |path| puts " - #{path}" }
|
97
56
|
end
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
LOGGER.debug("JSON content that failed to parse: #{file_content}")
|
104
|
-
raise JSON::ParserError, error_message
|
105
|
-
rescue StandardError => e
|
106
|
-
error_message = "Unexpected error while loading dictionary from '#{json_file}': #{e.message}"
|
107
|
-
LOGGER.error(error_message)
|
108
|
-
LOGGER.debug(e.backtrace.join("\n"))
|
109
|
-
raise
|
57
|
+
|
58
|
+
puts "Vamos usar o dicionário interativo em vez disso, tá bom?"
|
59
|
+
interactive_dictionary
|
60
|
+
else
|
61
|
+
interactive_dictionary
|
110
62
|
end
|
111
63
|
end
|
112
64
|
|
113
|
-
def
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
65
|
+
def interactive_dictionary
|
66
|
+
dict = {}
|
67
|
+
loop do
|
68
|
+
print "Term to search (or press Enter to finish): "
|
69
|
+
search = STDIN.gets.chomp
|
70
|
+
break if search.empty?
|
71
|
+
print "Term to replace: "
|
72
|
+
replace = STDIN.gets.chomp
|
73
|
+
dict[search] = replace
|
118
74
|
end
|
75
|
+
dict
|
119
76
|
end
|
120
77
|
|
121
|
-
def
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
# If UTF-8 reading fails, fall back to binary reading and force UTF-8 encoding
|
127
|
-
# This approach helps handle files with mixed or unknown encodings
|
128
|
-
truncated_file_name = File.basename(file_name)
|
129
|
-
LOGGER.warn("Invalid UTF-8 byte sequence in ...#{truncated_file_name}. Falling back to binary reading.")
|
130
|
-
text = File.read(file_name, encoding: 'BINARY')
|
131
|
-
text.force_encoding('UTF-8')
|
132
|
-
# Replace any invalid or undefined characters with empty string
|
133
|
-
text.encode!('UTF-8', invalid: :replace, undef: :replace, replace: '')
|
78
|
+
def process_files(origin_path, dict)
|
79
|
+
Dir.glob(File.join(origin_path, "**", "*"), File::FNM_DOTMATCH).each do |file_name|
|
80
|
+
next if File.directory?(file_name)
|
81
|
+
next if file_name.include?(".git/") || file_name.include?("node_modules/") # Ignore .git and node_modules folders
|
82
|
+
process_file(file_name, dict)
|
134
83
|
end
|
135
|
-
|
136
|
-
|
84
|
+
end
|
85
|
+
|
86
|
+
def process_file(file_name, dict)
|
87
|
+
text = File.read(file_name)
|
88
|
+
|
137
89
|
dict.each do |search, replace|
|
138
|
-
|
139
|
-
text_changed = true
|
140
|
-
end
|
90
|
+
text.gsub!(search, replace)
|
141
91
|
end
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
new_file_name = File.join(destination_path, new_relative_path)
|
148
|
-
else
|
149
|
-
new_file_name = File.join(origin_path, new_relative_path)
|
92
|
+
|
93
|
+
new_file_name = file_name.dup
|
94
|
+
|
95
|
+
dict.each do |search, replace|
|
96
|
+
new_file_name.gsub!(search, replace)
|
150
97
|
end
|
151
|
-
|
98
|
+
|
99
|
+
# Create the directory for the new file if it doesn't exist
|
152
100
|
new_dir = File.dirname(new_file_name)
|
153
101
|
FileUtils.mkdir_p(new_dir) unless File.directory?(new_dir)
|
154
|
-
|
155
|
-
if text_changed || new_file_name != file_name
|
156
|
-
File.write(new_file_name, text)
|
157
|
-
if destination_path || new_file_name != file_name
|
158
|
-
truncated_old = "...#{File.basename(file_name)}"
|
159
|
-
truncated_new = "...#{File.basename(new_file_name)}"
|
160
|
-
LOGGER.info("File #{destination_path ? 'copied' : 'renamed'} from #{truncated_old} to #{truncated_new}")
|
161
|
-
else
|
162
|
-
truncated_file = "...#{File.basename(file_name)}"
|
163
|
-
LOGGER.info("File contents updated: #{truncated_file}")
|
164
|
-
end
|
165
|
-
File.delete(file_name) if !destination_path && new_file_name != file_name
|
166
|
-
end
|
167
|
-
rescue => e
|
168
|
-
truncated_file = "...#{File.basename(file_name)}"
|
169
|
-
LOGGER.error("Error processing file #{truncated_file}: #{e.message}")
|
170
|
-
LOGGER.debug(e.backtrace.join("\n"))
|
171
|
-
end
|
172
102
|
|
173
|
-
|
174
|
-
|
175
|
-
|
103
|
+
# Write the changes to the new file name
|
104
|
+
File.write(new_file_name, text)
|
105
|
+
|
106
|
+
# If the filename has changed, delete the original file
|
107
|
+
unless new_file_name == file_name
|
108
|
+
File.delete(file_name) # Delete the original file
|
109
|
+
puts "File renamed from #{file_name} to #{new_file_name}, OK"
|
110
|
+
else
|
111
|
+
puts "File: #{file_name}, OK"
|
176
112
|
end
|
177
113
|
end
|
178
114
|
|
179
|
-
def remove_empty_directories(
|
180
|
-
Dir.glob(File.join(
|
115
|
+
def remove_empty_directories(origin_path)
|
116
|
+
Dir.glob(File.join(origin_path, "**", "*"), File::FNM_DOTMATCH).reverse_each do |dir_name|
|
181
117
|
next unless File.directory?(dir_name)
|
182
|
-
next if
|
118
|
+
next if dir_name.include?(".git/") || dir_name.include?("node_modules/") # Ignorar pastas .git e node_modules
|
119
|
+
next if dir_name == "." || dir_name == ".." # Ignorar diretórios especiais . e ..
|
183
120
|
if (Dir.entries(dir_name) - %w[. ..]).empty?
|
184
|
-
|
185
|
-
|
121
|
+
begin
|
122
|
+
Dir.rmdir(dir_name)
|
123
|
+
puts "Diretório vazio removido: #{dir_name}"
|
124
|
+
rescue Errno::ENOTEMPTY, Errno::EINVAL => e
|
125
|
+
puts "Não foi possível remover o diretório: #{dir_name}. Erro: #{e.message}"
|
126
|
+
end
|
186
127
|
end
|
187
128
|
end
|
188
129
|
end
|
189
130
|
end
|
190
131
|
|
191
|
-
class GenerateJson < Dry::CLI::Command
|
192
|
-
desc "Generate a new JSON file with an empty key-value pair"
|
193
|
-
|
194
|
-
option :output, type: :string, default: "rules", desc: "Name of the output JSON file (default: rules)"
|
195
|
-
option :path, type: :string, desc: "Path to save the JSON file (default: ~/.claiss/)"
|
196
|
-
|
197
|
-
example [
|
198
|
-
"",
|
199
|
-
"--output my_custom_rules",
|
200
|
-
"--path /custom/path/ --output my_rules"
|
201
|
-
]
|
202
|
-
|
203
|
-
def call(path:, rules:, destination: nil, **)
|
204
|
-
origin_path = File.expand_path(path)
|
205
|
-
destination_path = destination ? File.expand_path(destination) : nil
|
206
|
-
|
207
|
-
json_file = File.join(DEFAULT_JSON_DIR, "#{rules}.json")
|
208
|
-
|
209
|
-
begin
|
210
|
-
dict = load_dictionary(json_file)
|
211
|
-
rescue Errno::ENOENT => e
|
212
|
-
puts e.message
|
213
|
-
puts "Please make sure the JSON file exists in the ~/.claiss directory."
|
214
|
-
exit(1)
|
215
|
-
rescue JSON::ParserError => e
|
216
|
-
puts e.message
|
217
|
-
puts "Please check the JSON file for syntax errors."
|
218
|
-
exit(1)
|
219
|
-
rescue StandardError => e
|
220
|
-
puts "An unexpected error occurred: #{e.message}"
|
221
|
-
puts "Please check the log for more details."
|
222
|
-
exit(1)
|
223
|
-
end
|
224
|
-
|
225
|
-
process_files(origin_path, dict, destination_path)
|
226
|
-
remove_empty_directories(destination_path || origin_path)
|
227
|
-
|
228
|
-
puts "Done! Files have been refactored#{destination_path ? ' to the destination' : ' in place'}."
|
229
|
-
end
|
230
|
-
|
231
|
-
private
|
232
|
-
|
233
|
-
def ensure_json_extension(filename)
|
234
|
-
return filename if filename.end_with?('.json')
|
235
|
-
"#{filename}.json"
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
132
|
class FixRubyPermissions < Dry::CLI::Command
|
240
133
|
desc "Fix permissions for a Ruby project"
|
134
|
+
argument :path, required: true, desc: "The path of your Ruby project"
|
241
135
|
|
242
|
-
|
243
|
-
|
244
|
-
example [
|
245
|
-
"",
|
246
|
-
"path/to/ruby/project"
|
247
|
-
]
|
248
|
-
|
249
|
-
def call(path: ".", **)
|
136
|
+
def call(path: nil, **)
|
137
|
+
path ||= Dir.getwd
|
250
138
|
path = File.expand_path(path)
|
251
139
|
|
252
|
-
Dir.glob(File.join(path,
|
253
|
-
next if item ==
|
140
|
+
Dir.glob(File.join(path, "**", "*"), File::FNM_DOTMATCH) do |item|
|
141
|
+
next if item == "." || item == ".."
|
254
142
|
next if item.include?("node_modules/") # Ignore node_modules folder
|
255
143
|
if File.directory?(item)
|
256
144
|
File.chmod(0755, item)
|
@@ -259,25 +147,28 @@ module CLAISS
|
|
259
147
|
end
|
260
148
|
end
|
261
149
|
|
262
|
-
executable_files = [
|
150
|
+
executable_files = ["bundle", "rails", "rake", "spring"]
|
263
151
|
executable_files.each do |file|
|
264
|
-
file_path = File.join(path,
|
265
|
-
if File.exist?(file_path)
|
266
|
-
File.chmod(0755, file_path)
|
267
|
-
puts "Made #{file_path} executable"
|
268
|
-
end
|
152
|
+
file_path = File.join(path, "bin", file)
|
153
|
+
File.chmod(0755, file_path) if File.exist?(file_path)
|
269
154
|
end
|
270
155
|
|
271
|
-
puts "Permissions fixed for
|
156
|
+
puts "Permissions fixed for #{path}"
|
272
157
|
end
|
273
158
|
|
274
159
|
private
|
275
160
|
|
276
161
|
def fix_file_permissions(file)
|
277
|
-
|
278
|
-
|
162
|
+
current_permissions = File.stat(file).mode
|
163
|
+
|
164
|
+
if current_permissions & 0o100 != 0 # Check if the owner has execute permission
|
165
|
+
File.chmod(0755, file) # Maintain execution permission for owner, group, and others
|
166
|
+
elsif current_permissions & 0o010 != 0 # Check if the group has execute permission
|
167
|
+
File.chmod(0755, file) # Maintain execution permission for group and others
|
168
|
+
elsif current_permissions & 0o001 != 0 # Check if others have execute permission
|
169
|
+
File.chmod(0755, file) # Maintain execution permission for others
|
279
170
|
else
|
280
|
-
File.chmod(0644, file)
|
171
|
+
File.chmod(0644, file) # Otherwise, apply standard read/write permissions
|
281
172
|
end
|
282
173
|
end
|
283
174
|
end
|
@@ -285,4 +176,4 @@ end
|
|
285
176
|
|
286
177
|
require_relative "claiss/version"
|
287
178
|
require_relative "claiss/commands"
|
288
|
-
require_relative "claiss/cli"
|
179
|
+
require_relative "claiss/cli"
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: claiss
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Júlio Papel
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-02-08 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: dry-cli
|
@@ -52,34 +51,6 @@ dependencies:
|
|
52
51
|
- - "~>"
|
53
52
|
- !ruby/object:Gem::Version
|
54
53
|
version: 2.6.3
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: parallel
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 1.26.3
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 1.26.3
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: ruby-progressbar
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: 1.13.0
|
76
|
-
type: :runtime
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 1.13.0
|
83
54
|
description: CLI application Toolbox to manage CLAISS AI applications and deployments.
|
84
55
|
Some features may not work in all environments. Use with caution!
|
85
56
|
email:
|
@@ -102,7 +73,6 @@ licenses:
|
|
102
73
|
metadata:
|
103
74
|
source_code_uri: https://github.com/JulioPapel/claiss.git
|
104
75
|
documentation_uri: https://github.com/JulioPapel/claiss/blob/main/readme.md
|
105
|
-
post_install_message:
|
106
76
|
rdoc_options: []
|
107
77
|
require_paths:
|
108
78
|
- lib
|
@@ -117,8 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
87
|
- !ruby/object:Gem::Version
|
118
88
|
version: '0'
|
119
89
|
requirements: []
|
120
|
-
rubygems_version: 3.
|
121
|
-
signing_key:
|
90
|
+
rubygems_version: 3.6.3
|
122
91
|
specification_version: 4
|
123
92
|
summary: CLAISS AI CLI application Toolbox
|
124
93
|
test_files: []
|