Skip to content

Instantly share code, notes, and snippets.

@jerome-diver
Last active July 25, 2017 07:15
Show Gist options
  • Select an option

  • Save jerome-diver/56971332d53f93d63dcc1ba1ea8a86dc to your computer and use it in GitHub Desktop.

Select an option

Save jerome-diver/56971332d53f93d63dcc1ba1ea8a86dc to your computer and use it in GitHub Desktop.
con not find symbol &gourp, but sub group is export(:MANDATORY) { ...}
#---add.pm----
unit module add;
use Term::Choose;
use Prompt::Gruff::Export;
use check;
use datas;
######## PRIVATE FUNCTIONS ##################################################################
sub ask_add_new {
return prompt-for("Would you like to add an other one new repo ?", :yn(1));
}
my sub ask_repo_datas {
my ($title, $url);
$title= prompt-for( "Give a title for the new repo to add: " );
$url= prompt-for( "give me the repo url: ", :regex("^https://") );
return ($title, $url);
}
sub change_repo_datas(Str $title, Str $url){
$title = change_title( $title );
$url = change_url( $url );
return ($title, $url);
}
sub change_title(Str $title){
return prompt-for( "Change the title \"$title\" : " );
}
sub change_url(Str $url) {
return prompt-for( "Change the url \"$url\" : ", :regex("^https://") );
}
######## PUBLIC FUNCTIONS ###################################################################
# _Menu answer a) I want to add repos group
our sub group($yaml) is export(:MANDATORY) {
my $group_name;
while (1) {
$group_name= prompt-for( "Which name to give for this new group ?", :yn(1) );
if ( ! check.group_exist($yaml, $group_name) ) {
if ($group_name eq "") {
say "exit... ";
return 0;
} else {
$yaml.add_group( $group_name );
$yaml.save();
return;
}
} else { say "\ngroup exist allready... choose an other one name please."; }
}
return;
}
# _Menu answer b) i want to add repos
our sub repos($yaml) is export(:MANDATORY) {
my ( @group_list, $group_name, $title, $url );
my $add_repo= 1;
$yaml.datas.map: { @group_list.push: $_<group>; };
until ( defined $group_name ) {
$group_name= choose( @group_list,
:prompt("which group for add repos inside ? choose..."),
:index(1), :mouse(1), :layout(2) );
}
while ( $add_repo ) {
my $correct = 0 ;
($title, $url) = ask_repo_datas();
until ( $correct ) {
my $answer = check.repo_is_correct( $yaml, $group_name, $title, $url );
given "$answer" {
when "title exist" { say "title exist allreay in the database";
$title = change_title( $title ); }
when "url exist" { say "url exist allready in the database";
$url = change_url( $url ); }
when "want to change" { ( $title, $url ) = change_repo_datas( $title, $url ); }
when "remote repo failed" { say "remote repo does not exist or is down";
$url = change_url( $url ); }
when "all is ok" {
$yaml.add_repo( $group_name, $title, $url );
$yaml.save();
$correct = 1;
}
}
}
$add_repo = ask_add_new();
}
return;
}
#--datas.pm---
use YAML;
class datas {
has Str $.filename is rw;
has Array @.datas;
has Str $!directory= %*ENV<HOME> ~ "/.vim/installer";;
has Str $!repo_dir= %*ENV<HOME> ~ "/.vim/bundle";
has Str $!full_filename= $!directory ~ "/$!filename";
method new (Str $filename) {
return self.bless: filename => $filename;
}
method TWEAK {
self.initialize_directory();
self.initialize_filename_data();
my $thing = slurp $!full_filename;
# self.datas = load($thing);
}
method initialize_directory() {
unless $!directory.IO.d { mkdir $!directory or die "unable to create directory"; }
}
method initialize_filename_data() {
unless $!full_filename.IO.f {
my @default = [ { group => "default", repos => [ { url => "", title => "" } ] } ];
spurt $!full_filename, dump( @default );
}
}
method save {
spurt $!full_filename, dump(@!datas) or die "can not save datas.yml";
say "Datas has been saved.";
}
method add_group( $group_name ){
@!datas.push: { group => "$group_name", repos => [] };
}
has method add_repo($group_name, $title, $url) {
@!datas.map: {
if ( $_<group> eq $group_name ) {
$_<repos>.push: { title => "$title", url => "$url"}; }
}
}
}
---
- !Pair
key: repos
value:
- !Pair
key: title
value:
- !Pair
key: url
value:
- !Pair
key: group
value: default
...
#!/usr/bin/perl6
#use install;
use lib "/home/jerome/PROGRAMATION/Perl/Vim_plugger_6/";
use Term::Choose;
use datas;
use add :MANDATORY;
my $mode;
my $yaml = datas.new("my_pl6.yml");
my @menu0 = < List Add Modify Remove Install Uninstall Update Quit >;
my @menu_List = ( "Liste repos of group",
"Liste all the repos of database",
"List all installed repos" );
my @menu_Add = ( "Add new group", "Add new repos to group" );
my @menu_Remove = ( "Remove group", "Remove repos from group" );
my @menu_Modify = ( "Modify name of group", "Mofify repos" );
my @menu_Install = ( "Install repos from group", "Install all repos" );
my @menu_Uninstall = ( "Unisnstall repos from group", "Uninstall all repos" );
# Questions: what to do ?
sub menu($title, @list) {
my $title_ex = "\nWhat do you want to do ?\n $title";
$mode = choose( @list, :index(0), :layout(2), :mouse(1), :prompt($title_ex) );
return $mode;
}
while ( $mode = menu("Choose:", @menu0) ) {
given $mode {
when "List" {
my $action = menu("Print a list: ", @menu_List);
given $action {
when "List all the repos of database" { }
when "List repos of group" { }
when "List all installed repos" { } } }
when "Add" {
my $action = menu("Add something: ", @menu_Add);
given $action {
when "Add new group" { add::group($yaml); }
when "Add new repos to group" { add::repos($yaml); }
}
}
when "Modify" {
my $action = menu("Modification :", @menu_Modify);
given $action {
when "Modify a repos" { }
when "Modify name of group" { } } }
when "Remove" {
my $action = menu("Remove:", @menu_Remove);
given $action {
when "Remove repos from a group" { }
when "Remove group" { } } }
when "Install" {
my $action = menu("Install for vim", @menu_Install);
given $action {
when "Install repos from group" { } #install::repos_from_group($yaml); }
when "Install all repos" { } } }
when "Uninstall" {
my $action = menu("Uninstall repos:", @menu_Uninstall);
given $action {
when "Uninstall repos from group" { }
when "Uninstall all repos" { } } }
when "Update" { }
when "Quit" { exit; }
}
}
@jerome-diver

jerome-diver commented Jul 25, 2017

Copy link
Copy Markdown
Author

the yaml file syntax is wrong, it should have an Array content Hashes.
Instead, it contains an Array with two Hashes.
why ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment