From 6fc0459d81ffd4b169d9d60a98f0fe2970180c6a Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Tue, 15 Mar 2022 01:42:17 +0300 Subject: [PATCH] change pwd path --- shard.yml | 2 +- src/pmng.cr | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/shard.yml b/shard.yml index 59b9197..8b98be4 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: pmng -version: 0.1.0 +version: 0.2.1 authors: - Alexander Popov diff --git a/src/pmng.cr b/src/pmng.cr index 73b6b52..12d629d 100644 --- a/src/pmng.cr +++ b/src/pmng.cr @@ -2,6 +2,7 @@ require "option_parser" require "yaml" require "colorize" +# password serializer class Password include YAML::Serializable @@ -23,6 +24,7 @@ end VERSION = "0.2.1" +# program options begin OptionParser.parse do |parser| parser.banner = "pmng -- ver.: #{VERSION}\nThe very simple password manager for humans\n" @@ -50,11 +52,15 @@ rescue ex puts ex.message, "" end -password_file_path = PROGRAM_NAME.split("/") -password_file_path.pop -password_file_path.insert(-1, "pwd.yml") -password_file_path = password_file_path.join("/") +# password_file_path = PROGRAM_NAME.split("/") +# password_file_path.pop +# password_file_path.insert(-1, "pwd.yml") +# password_file_path = password_file_path.join("/") +# TODO: Fix later +password_file_path = "#{ENV["HOME"]}/.pwd.yml" + +# check password file exists if File.exists?(password_file_path) yaml = File.open(password_file_path) do |file| YAML.parse(file) @@ -72,22 +78,27 @@ while count < yaml.size count += 1 end +# main loop loop = true while loop + # shell prompt print "Enter URL (or :q for exit)\n> " password_string = gets + # if ':q' to close program if password_string.to_s == ":q" puts "Bye! 👋🏻" exit(0) + # if puts empty, retry prompt elsif password_string.to_s.size == 0 puts + # if ':h' to view help elsif password_string.to_s == ":h" puts "Help:\n-----" puts ":s - Return stats" - + # if ':s' to view Statistics elsif password_string.to_s == ":s" - puts "Statictics:\n----------" + puts "Statistics:\n----------" print "Elements: ".colorize(:yellow) puts new_array.size @@ -103,6 +114,7 @@ while loop end puts outdated_count + # list search password else new_array.each do |item| if item.url.includes?(password_string.to_s)