separate source file
This commit is contained in:
parent
5152598804
commit
626e7cbe0b
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
## 0.2.5b - [31/07/2022]
|
## 0.2.5b - [31/07/2022]
|
||||||
- ➕ - Added input timeout
|
- ➕ - Added input timeout
|
||||||
|
- ♻️ - Separate one source file
|
||||||
|
|
||||||
## 0.2.4 - [26/07/2022]
|
## 0.2.4 - [26/07/2022]
|
||||||
- ➕ - Added hint for fix file permissions error.
|
- ➕ - Added hint for fix file permissions error.
|
||||||
|
74
src/pmng.cr
74
src/pmng.cr
@ -2,73 +2,7 @@ require "option_parser"
|
|||||||
require "yaml"
|
require "yaml"
|
||||||
require "colorize"
|
require "colorize"
|
||||||
|
|
||||||
# password serializer
|
require "./pmng/*"
|
||||||
class Password
|
|
||||||
include YAML::Serializable
|
|
||||||
|
|
||||||
@[YAML::Field(key: "url")]
|
|
||||||
property url : String
|
|
||||||
@[YAML::Field(key: "email")]
|
|
||||||
property email : String
|
|
||||||
@[YAML::Field(key: "login")]
|
|
||||||
property login : String
|
|
||||||
@[YAML::Field(key: "password")]
|
|
||||||
property password : String
|
|
||||||
@[YAML::Field(key: "desc")]
|
|
||||||
property desc : String
|
|
||||||
@[YAML::Field(key: "profile_url")]
|
|
||||||
property profile_url : String
|
|
||||||
@[YAML::Field(key: "update")]
|
|
||||||
property update : Int32
|
|
||||||
end
|
|
||||||
|
|
||||||
VERSION = "0.2.5b"
|
|
||||||
PASSWORD_FILE_PATH = "#{ENV["HOME"]}/.pwd.yml"
|
|
||||||
ASCII_LOGO = "
|
|
||||||
██████╗ ███╗ ███╗███╗ ██╗ ██████╗
|
|
||||||
██╔══██╗████╗ ████║████╗ ██║██╔════╝
|
|
||||||
██████╔╝██╔████╔██║██╔██╗ ██║██║ ███╗
|
|
||||||
██╔═══╝ ██║╚██╔╝██║██║╚██╗██║██║ ██║
|
|
||||||
██║ ██║ ╚═╝ ██║██║ ╚████║╚██████╔╝
|
|
||||||
╚═╝ ╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝
|
|
||||||
"
|
|
||||||
|
|
||||||
# program options
|
|
||||||
begin
|
|
||||||
OptionParser.parse do |parser|
|
|
||||||
parser.banner = "The very simple password manager for humans\n"
|
|
||||||
|
|
||||||
parser.on "-v", "--version", "Show version" do
|
|
||||||
puts ASCII_LOGO.colorize(:yellow)
|
|
||||||
puts "The very simple password manager for humans.".colorize(:yellow)
|
|
||||||
print "Version ".colorize(:yellow)
|
|
||||||
puts VERSION.colorize(:red).mode(:bold)
|
|
||||||
print "\nURL to full change log: ".colorize(:yellow)
|
|
||||||
puts "https://git.a2s.su/iiiypuk/pmng/raw/branch/master/HISTORY.md".colorize(:green).mode(:bold)
|
|
||||||
|
|
||||||
exit(0)
|
|
||||||
end
|
|
||||||
parser.on "-h", "--help", "Show help" do
|
|
||||||
puts parser
|
|
||||||
|
|
||||||
exit(0)
|
|
||||||
end
|
|
||||||
parser.on "-g", "--generate-password", "Generate password" do
|
|
||||||
puts Random::Secure.urlsafe_base64(16, padding: false).colorize(:black).back(:white)
|
|
||||||
puts Random::Secure.urlsafe_base64(16, padding: false).colorize(:white).back(:blue)
|
|
||||||
puts Random::Secure.urlsafe_base64(16, padding: false).colorize(:white).back(:red)
|
|
||||||
|
|
||||||
exit(0)
|
|
||||||
end
|
|
||||||
parser.on "-t", "--unixtime", "Return local timestamp" do
|
|
||||||
puts Time.local.to_unix.colorize(:yellow).mode(:bold)
|
|
||||||
|
|
||||||
exit(0)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
rescue ex
|
|
||||||
puts ex.message, ""
|
|
||||||
end
|
|
||||||
|
|
||||||
# check password file exists
|
# check password file exists
|
||||||
if File.exists?(PASSWORD_FILE_PATH)
|
if File.exists?(PASSWORD_FILE_PATH)
|
||||||
@ -119,10 +53,10 @@ while loop
|
|||||||
print " for exit)\n".colorize(:white).mode(:bold)
|
print " for exit)\n".colorize(:white).mode(:bold)
|
||||||
print "> ".colorize(:green).mode(:bold)
|
print "> ".colorize(:green).mode(:bold)
|
||||||
|
|
||||||
begin # IO::TimeoutError
|
begin
|
||||||
STDIN.read_timeout = 60 # 1 minute
|
STDIN.read_timeout = USER_INPUT_TIMEOUT
|
||||||
password_string = STDIN.gets
|
password_string = STDIN.gets
|
||||||
rescue
|
rescue IO::TimeoutError
|
||||||
loop = false
|
loop = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
35
src/pmng/agrv_options.cr
Normal file
35
src/pmng/agrv_options.cr
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
begin
|
||||||
|
OptionParser.parse do |parser|
|
||||||
|
parser.banner = "The very simple password manager for humans\n"
|
||||||
|
|
||||||
|
parser.on "-v", "--version", "Show version" do
|
||||||
|
puts ASCII_LOGO.colorize(:yellow)
|
||||||
|
puts "The very simple password manager for humans.".colorize(:yellow)
|
||||||
|
print "Version ".colorize(:yellow)
|
||||||
|
puts VERSION.colorize(:red).mode(:bold)
|
||||||
|
puts "\nURL to full changes log: ".colorize(:yellow)
|
||||||
|
puts "https://git.a2s.su/iiiypuk/pmng/raw/branch/master/HISTORY.md".colorize(:green).mode(:bold)
|
||||||
|
|
||||||
|
exit(0)
|
||||||
|
end
|
||||||
|
parser.on "-h", "--help", "Show help" do
|
||||||
|
puts parser
|
||||||
|
|
||||||
|
exit(0)
|
||||||
|
end
|
||||||
|
parser.on "-g", "--generate-password", "Generate password" do
|
||||||
|
puts Random::Secure.urlsafe_base64(16, padding: false).colorize(:black).back(:white)
|
||||||
|
puts Random::Secure.urlsafe_base64(16, padding: false).colorize(:white).back(:blue)
|
||||||
|
puts Random::Secure.urlsafe_base64(16, padding: false).colorize(:white).back(:red)
|
||||||
|
|
||||||
|
exit(0)
|
||||||
|
end
|
||||||
|
parser.on "-t", "--unixtime", "Return local timestamp" do
|
||||||
|
puts Time.local.to_unix.colorize(:yellow).mode(:bold)
|
||||||
|
|
||||||
|
exit(0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
rescue ex
|
||||||
|
puts ex.message, ""
|
||||||
|
end
|
3
src/pmng/app_settings.cr
Normal file
3
src/pmng/app_settings.cr
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
VERSION = {{ `shards version "#{__DIR__}"`.chomp.stringify }}
|
||||||
|
PASSWORD_FILE_PATH = "#{ENV["HOME"]}/.pwd.yml"
|
||||||
|
USER_INPUT_TIMEOUT = 60
|
8
src/pmng/ascii_logo.cr
Normal file
8
src/pmng/ascii_logo.cr
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
ASCII_LOGO = "
|
||||||
|
██████╗ ███╗ ███╗███╗ ██╗ ██████╗
|
||||||
|
██╔══██╗████╗ ████║████╗ ██║██╔════╝
|
||||||
|
██████╔╝██╔████╔██║██╔██╗ ██║██║ ███╗
|
||||||
|
██╔═══╝ ██║╚██╔╝██║██║╚██╗██║██║ ██║
|
||||||
|
██║ ██║ ╚═╝ ██║██║ ╚████║╚██████╔╝
|
||||||
|
╚═╝ ╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝
|
||||||
|
"
|
18
src/pmng/password_class.cr
Normal file
18
src/pmng/password_class.cr
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
class Password
|
||||||
|
include YAML::Serializable
|
||||||
|
|
||||||
|
@[YAML::Field(key: "url")]
|
||||||
|
property url : String
|
||||||
|
@[YAML::Field(key: "email")]
|
||||||
|
property email : String
|
||||||
|
@[YAML::Field(key: "login")]
|
||||||
|
property login : String
|
||||||
|
@[YAML::Field(key: "password")]
|
||||||
|
property password : String
|
||||||
|
@[YAML::Field(key: "desc")]
|
||||||
|
property desc : String
|
||||||
|
@[YAML::Field(key: "profile_url")]
|
||||||
|
property profile_url : String
|
||||||
|
@[YAML::Field(key: "update")]
|
||||||
|
property update : Int32
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user